Hello,
I have a VS1053b configured as a slave device to an nRF52840 microcontroller. When I try to preform an ogg vorbis recording the resulting file is just low volume noise. I am using the line 1 input with a song played from the audio jack in my phone as the input signal. As far as I know the input signal meets the line input characteristics, and while I would not expect high quality audio from this set up I would expect to be able to record at least something resembling the input. Below Is my recording functions. If there are any errors in my set up or configuration please let me know. I have also included a snip on the input signal.
/*** begin - CORE functions ***/
#include "venc44k2q05.plg"
void VS1053bOggVorbisStartRecording(void) {
WriteSci(SCI_CLOCKF, HZ_TO_SC_FREQ(12288000) | SC_MULT_53_45X | SC_ADD_53_00X);
WriteSci(SCI_BASS,0x0000);
WriteSci(SCI_MODE, SM_RESET);
WriteMem(0xC01A, 0x2);
VS1053bLoadPlugin(encoder_plugin, sizeof(encoder_plugin)/sizeof(encoder_plugin[0]));
WriteSci(SCI_MODE, ReadSci(SCI_MODE) | SM_ADPCM | SM_LINE1);
WriteSci(SCI_RECGAIN, 1024); // SCI_AICTRL1
WriteSci(SCI_RECMAXAUTO, 0); // SCI_AICTRL2
WriteSci(SCI_RECMODE, 0); // SCI_AICTRL3
WriteSci(SCI_AIADDR, 0x34);
while(!nrf_gpio_pin_read(VS_SPI_DREQ_PIN));
}
void VS1053bOggVorbisStopRecording(void) {
WriteSci(SCI_AICTRL3, ReadSci(SCI_AICTRL3) | 0x0001);
}
uint8_t VS1053bOggVorbisRecordPacket(FIL* file, uint16_t packet_size) {
uint32_t bytes_written;
uint8_t packet[packet_size * 2];
//NRF_LOG_INFO("available words %d", ReadSci(SCI_RECWORDS));
for (int i = 0; i < packet_size; i++) {
uint16_t word = ReadSci(SCI_RECDATA);
packet[(2*i)] = (uint8_t)(word >> 8);
packet[(2*i)+1] = (uint8_t)(word & 0xFF);
}
//NRF_LOG_INFO("remaining words %d", ReadSci(SCI_RECWORDS))
FRESULT ff_result = f_write(file, packet, sizeof(packet), &bytes_written);
if (ff_result != FR_OK)
return ff_result;
return 0;
}
uint8_t VS1053bOggVorbisRecord(const char *file_name) {
FIL file;
FRESULT ff_result;
uint32_t bytes_written;
NRF_LOG_INFO("openning file %s", file_name);
ff_result = f_open(&file, file_name, FA_READ | FA_WRITE | FA_OPEN_APPEND);
if (ff_result != FR_OK)
return ff_result;
VS1053bOggVorbisStartRecording();
NRF_LOG_INFO("recording started");
while (1) {
if (ReadSci(SCI_AICTRL3) & 0x0001) {
VS1053bOggVorbisRecordPacket(&file, ReadSci(SCI_RECWORDS) - 1);
uint16_t last_word = ReadSci(SCI_RECDATA);
ff_result = f_putc((uint8_t)(last_word >> 8), &file);
if (!(ReadSci(SCI_AICTRL3) & 0x0002))
ff_result = f_putc((uint8_t)(last_word & 0xFF), &file);
//NRF_LOG_INFO("final packet recorded");
break;
} else if (ReadSci(SCI_RECWORDS) >= REC_PACKET_SIZE) {
//NRF_LOG_INFO("ADC left channel data", ReadSci(ADC
VS1053bOggVorbisRecordPacket(&file, REC_PACKET_SIZE);
//NRF_LOG_INFO("packet recorded");
}
if (GetRecordingUICommand() == STOP_RECORDING) {
VS1053bOggVorbisStopRecording();
//NRF_LOG_INFO("stop recording requested");
}
}
NRF_LOG_INFO("recording stopped");
ff_result = f_close(&file);
if (ff_result != FR_OK)
return ff_result;
VS1053HardwareReset();
VS1053SoftwareReset();
return -1;
}
/*** end - CORE functions ***/
Any input would be much appreciated. I am running out of ideas.
Thanks,
Connor
Ogg vorbis recording - non functional
-
- User
- Posts: 10
- Joined: Sat 2022-05-14 0:54
Ogg vorbis recording - non functional
- Attachments
-
- scope_3.png (57.06 KiB) Viewed 1987 times
Re: Ogg vorbis recording - non functional
1. Is the resulting file a valid Ogg Vorbis file? You can attach a small one for us to check.
2. venc44k2q05.plg is a stereo version of the app. Do you get the same/similar low-level signal on both channels? If you only use line 1, then you probably want to use venc44k1q05.plg for mono.
3. What if you clear the SM_LINE bit in the SCI_MODE register?
4. Does the normal encoding mode work? Do you get good monitoring through the analog outputs while recording?
2. venc44k2q05.plg is a stereo version of the app. Do you get the same/similar low-level signal on both channels? If you only use line 1, then you probably want to use venc44k1q05.plg for mono.
3. What if you clear the SM_LINE bit in the SCI_MODE register?
4. Does the normal encoding mode work? Do you get good monitoring through the analog outputs while recording?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
-
- User
- Posts: 10
- Joined: Sat 2022-05-14 0:54
Re: Ogg vorbis recording - non functional
Hello Pasi, thank you for the suggestions.
In responce to your queries, I listed the following remarks.
1. To the best of my knowledge I am recording valid .ogg files. I will attach an example of such a recording with the mono plugin to this reply.
2. When making stereo recordings I am seeing the same low volume noise on both right and left channels. Using the mono plugin did not seem to have an effect (still noise).
3. From reading the datasheet, I believe when the SM_LINE1 bit is clearing the VS1053b records from the mic input. Also from the datasheet, it states that the max amplitude of the mic input is 140mVpp. As my input signal is roughly 1.4Vpp I assumed this mic input would not work. I have now tried the mic input and could not perceive a difference (still noise).
3. What specifically are you referring to by "normal encoding"? likewise I'm not sure I understand what you mean by "good monitoring", when you say "analog outputs" are you refering to a pin I should be scoping or a register I should be checking?
Thanks again for your reply.
Cheers,
Connor
In responce to your queries, I listed the following remarks.
1. To the best of my knowledge I am recording valid .ogg files. I will attach an example of such a recording with the mono plugin to this reply.
2. When making stereo recordings I am seeing the same low volume noise on both right and left channels. Using the mono plugin did not seem to have an effect (still noise).
3. From reading the datasheet, I believe when the SM_LINE1 bit is clearing the VS1053b records from the mic input. Also from the datasheet, it states that the max amplitude of the mic input is 140mVpp. As my input signal is roughly 1.4Vpp I assumed this mic input would not work. I have now tried the mic input and could not perceive a difference (still noise).
3. What specifically are you referring to by "normal encoding"? likewise I'm not sure I understand what you mean by "good monitoring", when you say "analog outputs" are you refering to a pin I should be scoping or a register I should be checking?
Thanks again for your reply.
Cheers,
Connor
- Attachments
-
- mono_sample.OGG
- (1.39 MiB) Downloaded 122 times
-
- valid_sample.OGG
- (112.57 KiB) Downloaded 117 times
-
- User
- Posts: 10
- Joined: Sat 2022-05-14 0:54
Re: Ogg vorbis recording - non functional
I have a somewhat interesting update to make to this discussion.
I decided to try a stereo, two line set up with the right channel running into line 2 and the left channel running into line 1. On the firmware side, I loaded a stereo encoder package ("venc44k2q05.plg") and configured the line input with the mode register (WriteSci(SCI_MODE, ReadSci(SCI_MODE) | SM_ADPCM | SM_LINE1);). When I recorded audio with this configuration, I produced the following signal. One thing to note is that for testing purposes I cranked up the input volume.
Immediately, I noticed that it appears that the line 1 input signal (the top signal) is have some form of trimming filter placed on it (only the loudest/highest voltage readings are passed). From the ADC block diagram presented in the VS1053b datasheet, to me, this would indicate that the multiplexor is selecting the microphone amplifier input as opposed to line 1. Perhaps the raised volume is over-coming what ever switch is present in the amplifier and with the multiplexor selecting that line, it results in a trimmed signal?
Can this be the case? I am definitely setting the line input in the SM_MODE register and yet the line 1 signal is corrupted. Can the error be present in the multiplexor selection? Any advice on this topic would be much appreciated.
Thanks,
Connor
I decided to try a stereo, two line set up with the right channel running into line 2 and the left channel running into line 1. On the firmware side, I loaded a stereo encoder package ("venc44k2q05.plg") and configured the line input with the mode register (WriteSci(SCI_MODE, ReadSci(SCI_MODE) | SM_ADPCM | SM_LINE1);). When I recorded audio with this configuration, I produced the following signal. One thing to note is that for testing purposes I cranked up the input volume.
Immediately, I noticed that it appears that the line 1 input signal (the top signal) is have some form of trimming filter placed on it (only the loudest/highest voltage readings are passed). From the ADC block diagram presented in the VS1053b datasheet, to me, this would indicate that the multiplexor is selecting the microphone amplifier input as opposed to line 1. Perhaps the raised volume is over-coming what ever switch is present in the amplifier and with the multiplexor selecting that line, it results in a trimmed signal?
Can this be the case? I am definitely setting the line input in the SM_MODE register and yet the line 1 signal is corrupted. Can the error be present in the multiplexor selection? Any advice on this topic would be much appreciated.
Thanks,
Connor
- Attachments
-
- block.PNG (28.58 KiB) Viewed 1968 times
-
- singal.PNG (129.42 KiB) Viewed 1968 times
-
- REC_01.OGG
- (1.27 MiB) Downloaded 132 times
-
- User
- Posts: 10
- Joined: Sat 2022-05-14 0:54
Re: Ogg vorbis recording - non functional
Final update to this thread.
I swapped a new VS1053b chip into my development set up and the whole things runs perfectly now. I believe I damaged the microphone amplifier/multiplexor system earlier in development. Major take always from this project so far have been that the mic and line inputs have little to no protection entering the SOC; take care not to generate erroneous signals that exceed the electrical limits of those pins.
Cheers,
Connor
I swapped a new VS1053b chip into my development set up and the whole things runs perfectly now. I believe I damaged the microphone amplifier/multiplexor system earlier in development. Major take always from this project so far have been that the mic and line inputs have little to no protection entering the SOC; take care not to generate erroneous signals that exceed the electrical limits of those pins.
Cheers,
Connor
Re: Ogg vorbis recording - non functional
Great that it was resolved. A few notes for future readers:
The analog inputs have protection diodes to AVDD and ground (like all pins have diodes to their respective supply voltage and ground), but of course they can also get broken due to high voltages, e.g. ESD.
The SM_LINE1 bit in SCI_MODE is directly controlling the microphone amplifier, there is no firmware intervention.
The built-in encoding mode in ROM provides monitoring of the signal to the analog outputs (LEFT / RIGHT). If you have a headphone output in the system, you can thus determine if the issue is in the data transfer between vs10xx and your controller, or with the external analog circuitry between the audio source and the analog input pins of the vs10xx. You don't even need to read out the data to get the monitoring. SCI_VOL only affects the monitoring volume, not the encoded signal.
Tools such as ogginfo and oggcrc ( source code available from viewtopic.php?t=2376 ) can be used to analyze the resulting Ogg Vorbis file. (I checked REC_01.OGG, and apart from missing the last frame flag, it seems valid.)
The analog inputs have protection diodes to AVDD and ground (like all pins have diodes to their respective supply voltage and ground), but of course they can also get broken due to high voltages, e.g. ESD.
The SM_LINE1 bit in SCI_MODE is directly controlling the microphone amplifier, there is no firmware intervention.
The built-in encoding mode in ROM provides monitoring of the signal to the analog outputs (LEFT / RIGHT). If you have a headphone output in the system, you can thus determine if the issue is in the data transfer between vs10xx and your controller, or with the external analog circuitry between the audio source and the analog input pins of the vs10xx. You don't even need to read out the data to get the monitoring. SCI_VOL only affects the monitoring volume, not the encoded signal.
Tools such as ogginfo and oggcrc ( source code available from viewtopic.php?t=2376 ) can be used to analyze the resulting Ogg Vorbis file. (I checked REC_01.OGG, and apart from missing the last frame flag, it seems valid.)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook