Hello,
So I have been able to save data from both ADC's (ADC0,ADC1) using the DMA for 2 channels and then write data to SD card in a .wav file on a teensy 3.5.
My issue is that I can only open my files in audacity. Which is ok for now. And im seeing exatly what I should see,which is great.....
But I cant open them in Windows Media Player or in R. They both expect signed 16 bit PCM....but I believe I have the correct header for setting up a signed 16 bit PCM header for a .wav file. And my data is signed 16 bit.
Samplerate: 49152 Hz <-Ive tried 44100 and 48000 and neither open in windows media or R,neither does 49152. I chose the value 49152Hz so my files were 15 seconds long and didnt have any decimals after like 15.2354 seconds.
Resolution: 16bit
Number of channels : 2
And heres what the .wav fileheader is based off of:
http://soundfile.sapp.org/doc/WaveFormat/
And heres is my struct and followed by wave file header code:
STRUCT:
WAV FILE HEADER CODE
From the looks of it,its setup for signed 16bit PCM, my data is signed 16bit btw...so I have no idea currently,why I can only open them in audacity and then have to convert them to signed 16 bit PCM and then they open in windows and R.....But if im doing everything correctly(likely not the case) is there a program that can open up a batch of .wav files and convert them,or would I be better off using say trying matlab and opening the files and converting or something?
So I have been able to save data from both ADC's (ADC0,ADC1) using the DMA for 2 channels and then write data to SD card in a .wav file on a teensy 3.5.
My issue is that I can only open my files in audacity. Which is ok for now. And im seeing exatly what I should see,which is great.....
But I cant open them in Windows Media Player or in R. They both expect signed 16 bit PCM....but I believe I have the correct header for setting up a signed 16 bit PCM header for a .wav file. And my data is signed 16 bit.
Samplerate: 49152 Hz <-Ive tried 44100 and 48000 and neither open in windows media or R,neither does 49152. I chose the value 49152Hz so my files were 15 seconds long and didnt have any decimals after like 15.2354 seconds.
Resolution: 16bit
Number of channels : 2
And heres what the .wav fileheader is based off of:
http://soundfile.sapp.org/doc/WaveFormat/
And heres is my struct and followed by wave file header code:
STRUCT:
HTML:
struct fileheader {
char mainChunkId[4]; /* "RIFF" */
uint32_t mainChunkSize; /* file length in bytes */
char mainChunkFormat[4]; /* "WAVE" */
char fmtChunkId[4]; /* "fmt " */
uint32_t fmtChunkSize; /* size of FMT chunk in bytes (usually 16 for PCM) */
uint16_t format_tag; /* 1=PCM, 257=Mu-Law, 258=A-Law, 259=ADPCM */
uint16_t num_chans; /* Number of channels/pins used */
uint32_t sample_rate; /* Sampling rate in samples per second */
uint32_t byteRate; /* Byte rate = SampleRate * NumChannels * BitsPerSample/8 */
uint16_t blockAlign; /* 2=16-bit mono, 4=16-bit stereo */
uint16_t bits_per_samp; /* Number of bits per sample */
char SubtwoChunkId[4]; /* "data" */
uint32_t SubtwoChunkSize; /* data length in bytes (filelength - 44) */
} wavheader;
WAV FILE HEADER CODE
HTML:
void setupWAVHeader() {
uint16_t resolution0 = adc->adc0->getResolution();
uint32_t SubtwoChunkSizeCalc = (FILE_SIZE * 2) * (resolution0 / 8); // =NumSamples * NumChannels * BitsPerSample/8.
//RIFF chunk descriptor
char riff[4] = {'R', 'I', 'F', 'F'};
strncpy(wavheader.mainChunkId, riff, 4);
wavheader.mainChunkSize = 36 + SubtwoChunkSizeCalc; // Size of the entire File -8 bytes for the two fields not included in this count (ChunkID and ChunkSize)
char wav[4] = {'W', 'A', 'V', 'E'};
strncpy(wavheader.mainChunkFormat, wav, 4);
//Subchunk1 --> fmt sub-chunk
char fmt[4] = {'f', 'm', 't', ' '};
strncpy(wavheader.fmtChunkId, fmt, 4);
wavheader.fmtChunkSize = 16; //16 for PCM
wavheader.format_tag = 1; // 1 is PCM (Pulse-code modulation used for sampled analog signals)
//Subchunk1 sound attributes
wavheader.num_chans = numChannels;
wavheader.sample_rate = adc_freq / ChannelPinNumber0;
wavheader.byteRate = adc_freq / ChannelPinNumber0 * (resolution0 / 8) * numChannels;
wavheader.blockAlign = numChannels * (resolution0 / 8);
wavheader.bits_per_samp = resolution0;
//ExtraParamSize = ... doesn't exist when using PCM
//Subchunk2 contains size of data and actual sound:
char data[4] = {'d', 'a', 't', 'a'};
strncpy(wavheader.SubtwoChunkId, data, 4);
wavheader.SubtwoChunkSize = SubtwoChunkSizeCalc;
}
From the looks of it,its setup for signed 16bit PCM, my data is signed 16bit btw...so I have no idea currently,why I can only open them in audacity and then have to convert them to signed 16 bit PCM and then they open in windows and R.....But if im doing everything correctly(likely not the case) is there a program that can open up a batch of .wav files and convert them,or would I be better off using say trying matlab and opening the files and converting or something?
Last edited: