8bit raw audio Hioutput

Hi,
I use Win10 with latest updates and Audacity 2.3.3 (german)

I want convert a short wav file (mp3, 8KS, 8 bit) to a raw audio file (8kS, 8 bit)
for use with an ATMEGA.
I found a solution in
https://www.hellomico.com/getting-started/convert-audio-to-raw/

Because I could not load my MP3 wav file I tried this method using the laptops microphone.

Unfortunately the outputfile has 28kB for about 1 second audio.
I guess the reason is, that audacity uses 32bit floating point.
Otherwise reading the raw file with a hex editor, the output do not look like 32 bit numbers, so I do not know how to convert this.
4 lines as example:

}}|||||{{{{{{{zz
zzzzzzyyyyyyyyyy
yyyxxxxxxxxxxxxx
xxxyyyyyyyyyyyzz
zzzzz{{{{{{||||}

Is there a way to configure the outputfile for 8bit? I did not found this

tnx for an answer
Guenter

Btw: I converted the wav files to ogg and read this with audacity and tried the
procedure mentioned above: similar result.

Your (confusing) hellomico instructions do specify saving as 16bit WAV at one point.

There are RAW export options in Audacity …
https ://manual.audacityteam.org/man/other_uncompressed_files_export_options.html

Did you try re-opening the raw file in Audacity?

For testing purposes, try an 8-bit WAV file. Since a WAV file has a header, you can check it with [u]MediaInfo[/u] to check the sample rate and bit-depth, etc. (MediaInfo won’t work with raw data.)

If your ATmega player is working and the bit-depth & sample rate are correct, it should play the WAV file. Since your player is reading raw data it will read the bytes in the WAV header and convert them to audio and you’ll hear a noise-glitch at the beginning before the recorded sound plays, but it should play.

=raw audio file (8kS, 8 bit)

Your linked instructions say to use a sample rate of 62,500 (62.5 kHz). Since you’re at 8-bits (one byte per sample), one second should be 62,500 bytes.

Otherwise reading the raw file with a hex editor, the output do not look like 32 bit numbers, so I do not know how to convert this.
4 lines as example:

}}|||||{{{{{{{zz
zzzzzzyyyyyyyyyy
yyyxxxxxxxxxxxxx
xxxyyyyyyyyyyyzz
zzzzz{{{{{{||||}

The ASCII character conversions are meaningless since this isn’t a text file. (The hex editor doesn’t know that so it will show the ASCII conversion for any value that can be converted to ASCII.)

The hex data (00-FF hex) for an audio file should “look random” since you’re looking a sampled waveform at one byte at a time. You can’t determine the bit-depth by looking at the bytes. (That information is contained in a WAV file header, but raw files don’t have a header.)

Try making a silent file. There are no standards for “raw” files but 8-bit WAV files are normally unsigned so silence gives you a file full of ‘80’ hex bytes (128 decimal) following the header. I tried a raw file and I got the same thing (without the header, of course) 16-bit WAV files use signed integers so silence gives you a file full of zeros.

Because I could not load my MP3 wav file

You can load anything you want but it’s a question of what your firmware can read. You’d need an MP3 decoder and the ATmega chip isn’t fast enough to decode MP3 in real time.

Raw PCM data is a lot “simpler” but the format is strict because the firmware has to know the exact format in advance. It’s the same if you open a raw file in Audacity… You have to enter the correct parameters.

…It would be pretty simple for the firmware to read a WAV header and make sure the format is correct (or acceptable) but whoever wrote the library didn’t bother with that. Of course on a computer or other any “normal” audio player, the file header is read and any necessary conversion is done so that a variety of formats can be played.

\

…The tricky thing with the ATmega chip is that it doesn’t have a DAC so these libraries use PWM to “fake” the analog. (With an 8-bit DAC, you’d just write-out the raw 8-bit data at the correct sample rate and you’d be done!

BTW - Don’t connect the unfiltered PWM to your stereo system or to a “good amplifier” that you care about! PWM is a “loud” high-frequency/ultrasonic signal (usually 5V from the ATmega chip) and “bad things” can happen.

Thank you for the answers.

Reopening workes with import raw data.

Thanks to the link from Trebor:I found the configuration for 8bit unsigned pcm now and created a wav and a raw file.
Bofore I also mixed to mono and have 8kS (other than in the link, sorry I did not mentioned this)
The new wave file is playable with Win but is 111kB ( for 1 second) and should be about 8kB!!

The Atmega should simply send the Byte data to R/2R network with 8kByte /s. This works ok.
The application is sound of railway engine :slight_smile: for models.

I read about the wav header on wikipedia and can remove it if necessary.

I exspected &H80 for silent parts and otherwise random data for other parts, but the silence part at the beginning looks like :
7F 7F 7F 7F 7F 7F 7F 7F 7F 7F 7F 7F 80 80 80 7F

Sorry, there was a missunderstang ( due to my english :frowning: ):

“Because I could not load my MP3 wav file”

I meant,I could not load the mp3 to Audacity, …

Still the question: why the file is not 8kB?

Guenter

The new wave file is playable with Win but is 111kB ( for 1 second) and should be about 8kB!!

But the hellomco.com instructions say a sample rate of 62,500Hz.

For uncompressed files:
File size in bytes = (Bit depth/8) x Number of channels x Sample rate x Playing Time in seconds.

For a raw file that’s exactly what you should have. (62,500 bytes per second.)

If it’s a WAV file, the standard WAV header adds just 44 bytes. If there’s embedded metadata (especially embedded album artwork) that will add to the file size. In your case you wouldn’t have artwork and Audacity’s metadata doesn’t support artwork.

The [u]SimpleSDAudio page[/u] says:

62.500 kHz (fullrate) / 31.250 kHz (halfrate) sampling rate @ 16 MHz
31.250 kHz (fullrate) / 15.625 kHz (halfrate) sampling rate @ 8 Mhz

So, I assume there is a fullrate/halfrate switch in the software. The 8/16MHz is the CPU clock so that depends on your hardware.

I don’t understand this:

8-Bit PWM output - no external DAC required 16-Bit emulation using 2x 8-Bit PWM output - requires only two resistors

I know the regular ATmega PWM is 8-bits, but up-sampling doesn’t gain you anything so maybe it can optionally read 16-bit files?



The Atmega should simply send the Byte data to R/2R network with 8kByte /s. This works ok.

So, it’s working now?

I exspected &H80 for silent parts and otherwise random data for other parts, but the silence part at the beginning looks like :
7F 7F 7F 7F 7F 7F 7F 7F 7F 7F 7F 7F 80 80 80 7F

That’s OK. Since it’s unsigned the mid-point of the 8-bit waveform (or silence) is 127.5, so with integers either 127 (7Fh) or 128 (80h). But when I generated a silent file in Audacity I got 80 so I think that’s “technically correct” for a WAV file. And, standard mathematical rounding practice would round 127.5 up to 128. But, there are no “standards” for raw files.

Sorry, there my be still a missunderstanding:

I used the hellommco.com page as an instruction, how to use Audacity (I did not use Audacity before). I neither use their software nor an arduino and do not know any details about.

My Atmega also do not use PWM; my very simple (BASCOM) program copy the sound bytes to Port D. The connected R/2R network convert then to analog. (work like a DA converter).
I store the sound data internally, so I have to use 8k Samplerate due to limited space.

Therefore I set the sample rate in Audacity to 8k (not 62,5k); audacity show this on the left side beneeth the track

ok the 80 7F lines are correct

?? still do not know how to get a smaaller file

Guenter

?? still do not know how to get a smaller file.

Strange… It works for me… I exported an (approximately) 1 second, 8kHz, mono file as 8-bit raw and I got an (approximately) 8KB file.

Or try a WAV file again. If it’s not 8K per second* MediaInfo should give some clues about what’s wrong. If it is OK, try it with your microcontroller. If it works you can strip-out the WAV header later.




\

  • As you probably know you can multiply bytes-per-second x 8 to get the bitrate (bits-per-second) so if everything is correct MediaInfo should show a bitrate of 64 kbps.


    P.S.
    I don’t know if this will help at all, but you can also generate a 1 second square wave with an amplitude of ''1" (1 = 100%). That will give you an 8-bit file full of 00’s & FF’s that you can look at with your hex editor. And again, that can be a WAV file or a raw file. I used the 1kHz and it shows-up as a nice diagonal pattern in the hex editor (that was a raw file).

Mediainfo show 48kHz, that is the samplerate of the ogg input file.

The 4musik_wav_to_ogg converter has no output lower than 32kHz.
With a 32kHz off file I got a (Audacity) 32kHz wav file (72kByte only)
For any reason Audacity ignore the 8k Configuration when exporting (when I press tracks -mix-mix and rendering: 8k jumps back to 32k ).

My original file is a mpeg3 wav file (8kS. 8bit). I could not load it to Audacity because ffmpeg is missing and I did not found a solution to add this.

I have no problems using Linux, Audacity with ffmpeg should work with me.

Other solution I will try first (I think that you suggested this):
I will calculate a mean value of any 4 bytes from the 32kHz raw file, which will give the 18kB file
Doing this an testing wil take time …

Guenter

Mediainfo show 48kHz, that is the samplerate of the ogg input file.

OK, that’s easy! I think we’ve go it now! In the bottom left corner of the Audacity window there is a box labeled “Project Rate”. Change that to 8000.

When you 1st open Audacity it will default to however you’ve got Audacity configured. Then if you open a file it will change to the sample rate of the file you just opened.

When you change the “Project Rate” to 8000, nothing happens immediately but you’ll get 8Khz when you export.

…In those “original instructions” (which aren’t exactly what you want to do) it tells you to change the project rate to 62,500.

You should have also had a clue when you re-opened the raw file in Audacity. If you open a raw 48kHz file but you type-in a sample rate of 8000Hz, the file would play-back at 1/6th speed and 1/6th the original pitch and take 6 times as long to play. :wink:

Now it is working
Thank you
Guenter