Shop OBEX P1 Docs P2 Docs Learn Events
Playing Wav files... — Parallax Forums

Playing Wav files...

cavelambcavelamb Posts: 720
edited 2012-02-09 09:54 in Propeller 1
It didn't work Saturday.
Then this morning I had an idea and rebuilt the audio output circuit - and it worked as advertised.

I'm using Ray Allen's 8 bit wav player from the OBX and playing the Microsoft Windows sign-on music
that was included in the example. That's about 3 or 4 seconds or so long?

But Ray jumps over the header and say "so you better have the right format!"
Sounds like good advice, but what format is that????

Anyway, it runs from EEPROM, so now when it powers up it makes "real" computer sound -
then goes and blinks it's LED. Some habits are had to break...

Great big sound - from a tiny little computer.

Looking forward to getting the Ships' Bell Dinger digitized next.

Ray? You out there?
«1

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-02-07 01:39
    Just connect an SD card and play much larger 16-bit wav files instead, it's very easy. The audio output circuit is only a resistor and a capacitor, about as simple as it can get. I use 220 ohms and 100nf for these components and Audacity (on Linux) for converting to 16-bit signed wave files. Not sure what your software does with the wave file but mine reads the file header for the sample rate etc.
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-02-07 01:45
    Like many, I started with Ray's code and then expanded on it to create a commercial product. You can find the audio play code in this thread:
    -- http://forums.parallax.com/showthread.php?123900-EFX-TEK-shows-the-Propeller-AP-16-WAV-Audio-Player-at-Parallax-wow!

    [Edit] I should have qualified that: it's if you want to start playing WAV files (stereo, up to 44.1kHz) from an SD card.
  • RaymanRayman Posts: 14,845
    edited 2012-02-07 06:54
    Glad you got it!

    The format for playing from HUB RAM (loaded from eeprom) is:
    8-bit PCM mono 16000 or 8000 sample/second WAV
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-02-07 08:48
    I use 220 ohms and 100nf for these components and Aud......
    That gives a cutoff frequency of 7.2 kHz and that isn't good enough for CD quality playback.... It will sound a little bit muffled.
    At least it's better than the "Propeller standard" of 1.6 kHz. (all Parallax boards uses it.... argh..)

    /Johannes
  • cavelambcavelamb Posts: 720
    edited 2012-02-07 10:18
    Rayman wrote: »
    Glad you got it!

    The format for playing from HUB RAM (loaded from eeprom) is:
    8-bit PCM mono 16000 or 8000 sample/second WAV

    Thank you, Rayman! That's the info I needed to digitize my bell.

    Jakak, Ahle2i:
    While the SD card suggestion sounds plausable, the extra load on the battery isn't.
    And that's part of the project spec - to be portable and self contained - battery powered.
    Managing power will be one of the bigger headaches - er Challenges? - in this project.
    Turn off audio amp power when not needed, and even see if I can put the CPU to sleep (sort of)
    to help extend battery life.

    The RTC has it's own battery support and it will run for ages.
    But I don't (yet) see a way to have the RTC alarm power up the Propeller, et al.
    Working on it though.

    JonnyMac:
    Thanks for that link.
    That's pretty much what I'm trying to do as well.

    And to all who donate their work to the OBX - you guys make it possible for us newbies.
    BIG thanks

    Richard
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-07 10:26
    Ahle2 wrote: »
    That gives a cutoff frequency of 7.2 kHz and that isn't good enough for CD quality playback.... It will sound a little bit muffled.
    At least it's better than the "Propeller standard" of 1.6 kHz. (all Parallax boards uses it.... argh..)

    /Johannes

    Johannes,

    What values do you suggest?
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-07 11:08
    I don't know of this helps at all or if you already know, it audacity is on windows.
    And if you want to get true eight bit and sixteen bit sounds, programs like Raster music maker and VGM music maker are free to download and can export .wav files. But you wuld need to use an sd card, because even short ones average 1mb....
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-02-07 11:36
    Oooor.... You could let the Propeller do the synthesis by itself in a single cog and have results like....

    The whole tune takes 1.4 kB and that includes both instrument and music data.
    After some optimizations Retronitus now has got almost twice the sample rate of CD audio.

    /Johannes
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-07 14:25
    That's is genius!!!!!!!!!!!!!!!! that's so awesome!!!!!!! I love making old retro music, plus with the fact that I already am learning about video drivers, I might well look into sounds ones too!!!!! But which particular emulation routine are you using. Plus 1.4kb in a single cog with emulation is intense!!!!!!!
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-07 14:58
    That's Ahle's own "Retronitus" sound engine. Look at his signature for more sound engines.
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-07 15:21
    Well I know that much but he has SIDcog, AYcog, and SNEcog
    @Ahle2, have you ever thought of making a pokey cog emulator?
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-07 15:31
    • SIDcog
    • AYcog
    • SNEcog
    • Retronitus <- this one
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-07 15:47
    That's pretty freakin boss.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-02-07 16:24
    Why can't you use an SD card? SD cards enter automatic sleep mode of less than 250ua as long as you don't clock them (which doesn't happen on a Prop). Read in as much as you can into RAM and sleep for a while. I have also used active switching of the SD power rails in some designs.

    Anyway Richard I think you just ran into the house all excited and out of breath "it didn't work this morning" because you didn't give us any of the details that you now have since you have your breath back. I suppose you may have another thread somewhere but I'm not familiar with it.
  • cavelambcavelamb Posts: 720
    edited 2012-02-07 18:02
    Oh Man! You got me, Peter. I probably even giggled out loud (blush)
    It WAS pretty exciting when it actually made music.

    The project is a Ships Bell Clock. It dings the bell every half hour, but in a traditional nautical pattern.
    I'm a sailor and like the bells. It marks the passage of time through he day, kinda like a grandfather clock does.

    I have a ships bell simulator on my desk computer. I thought I'd try to make a portable version that I could
    take out on the boat as well. That's actually how I came to meet the Propeller. Can you imagine trying to
    play sounds like that on a PIC?

    So, I ordered a couple of Propeller boards and a couple of real time clock boards and sat down to make
    that "I wish I had a" daydream come true.

    At first I wasn't sure that the prop could do it all by itself, but now I'm convinced it can.

    The SD card keeps getting better and better! I had no idea it went to sleep.

    As for the Propeller, in this project it doesn't do anything most of the time -
    only twice and hour for a few seconds.

    Most logic chips use more power when they run faster. And they use more power
    when more transistors are flippin' on and off.
    So I was thinking of 1) running as slow as possible until time to go to work.

    It will evolve, I'm sure...

    Just takes time.

    and 2) maybe do a long series of waitCnts (29.9 minutes worth) until a few seconds before the mark.
    Then check the RTC until time to ding, and take a nap again.
  • cavelambcavelamb Posts: 720
    edited 2012-02-07 18:05
    Ahle2 wrote: »
    Oooor.... You could let the Propeller do the synthesis by itself in a single cog and have results like....

    The whole tune takes 1.4 kB and that includes both instrument and music data.
    After some optimizations Retronitus now has got almost twice the sample rate of CD audio.

    /Johannes

    Thou shalt not covet thy neighbor's scope...
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-07 18:06
    Now I know how you feel cavelamb! Finally getting the thing to work freakin rocks!!! And so does SIDcog!!!!!!,
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-07 18:12
    Neighbor's scope?? I'm a little confused.................
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-07 18:15
    Oh but the Retronitus, it sounds fantastic!!!
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-02-07 19:25
    You also have the other option of using serial flash such as the 2Mbyte M25P16-VMN6P which in a one-off price is only $1.77. This is a little bit simpler and more compact than SD or microSD. The serial Flash chips all work pretty much the same and you can just treat them as a raw block device rather than worrying about a file system. Of course the Prop is overkill really but it is more fun than squeezing an 8-bit micro just because it's low-power.
  • cavelambcavelamb Posts: 720
    edited 2012-02-08 09:48
    It looks like the SD card is going to be a necessary evil after all...

    The waveform below is a double stroke bell - and although only 27K bytes, it sounds great.
    I thought I'd try to skip past the first ding to the start of the second ding to play a single stroke.
    (for those unfamiliar with nautical bells they come in patterns of one or two strokes)
    Thereby getting both of the necessary sounds from a single data set.

    Two problems with that though...
    1) 27Kb doesn't leave much room in 32kb EEPROM for code.
    2) While it sounds fine on the PC, it doesn't play on the propeller.

    I'm going to need sharper tools for converting wav files to something usable.
    Or maybe look at MP3 players.

    But either way, it's going to need more storage space.
    The Propeller Platform from Gangster Gadgets has a micro SD socket already on board, so
    that's the one I'm using now.

    Waveform.JPG
    800 x 640 - 73K
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-02-08 09:52
    Duane Degn wrote: »
    Johannes,
    What values do you suggest?
    220 ohm and 33 nF gives a cutoff frequency of ~21 kHz.
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-08 09:59
    I know this will of help
    I forgot what's it called, I think like VIZ media player or something, but converts any kind of playabe music or video file into any other kind of music file imaginable!
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-02-08 10:02
    That's is genius!!!!!!!!!!!!!!!! that's so awesome!!!!!!! I love making old retro music, plus with the fact that I already am learning about video drivers, I might well look into sounds ones too!!!!! But which particular emulation routine are you using. Plus 1.4kb in a single cog with emulation is intense!!!!!!!
    This is not an emulation of any PSG or existing sound synthesis. When you are trying emulate an existing hardware, you are forced to do things the same way as the original does it. (you can't cheat)
    Retronitus uses "every trick in the book" and relies on both the strength and limitations of the Propeller to achieve good results without "eating cycles for breakfast"... The end result is high sample rate and low aliasing distortion.
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-08 10:07
    Thats even more genius!!! Complete from scratch synthesis using the propeller!!!!????? That's crazy, but the basis of great things started from a crazy idea!! But in all seriousness that's awesome and very interesting. And to correct my earlier post, it's VLC media player, not VIZ. Do not search VIZ because you will get anime, not a media play that can stream and convert.
    (^_−)−☆ apologies for confusion.....
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-02-08 10:09
    Well I know that much but he has SIDcog, AYcog, and SNEcog
    @Ahle2, have you ever thought of making a pokey cog emulator?

    Well, the Pokey is an interesting and relatively simple sound chip to emulate. It's an excellent chip for sound effects.
    The problem is that it only has got an 8bit frequency register per channel and that will make everything sound out of tune.
    So for music it isn't very pleasant to listen to.
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-08 10:13
    I see. That's makes sense. I've worked a lot with the atari 800 for fun, and RASTER music tracker. The pokey has quite a number of helpful parameters, and can even adjust the intonation of a particular note. Plus it has filters, and I don't know if other sounds chips use that, except maybe SID, but I'm no expert.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-02-08 11:08
    Hi Johannes,

    What are we looking at on the 'scope? There are two traces, but with some kind of chopping.

    It's remarkable sound. Still wondering how you did it! My son who has much more of a musical ear than I do, discerned 4 sections of 4 bars each in the loop. Is that right?
  • SONIC the HedgehogSONIC the Hedgehog Posts: 321
    edited 2012-02-08 11:13
    That's makes a little sense, but I didn't really dissect it with my ears, not like they are the best or anything, I was just enjoying the endless sound capabilities with propeller, but that does sound very similar.
  • groggorygroggory Posts: 205
    edited 2012-02-08 11:37
    cavelamb wrote: »
    It looks like the SD card is going to be a necessary evil after all...

    The waveform below is a double stroke bell - and although only 27K bytes, it sounds great.
    I thought I'd try to skip past the first ding to the start of the second ding to play a single stroke.
    (for those unfamiliar with nautical bells they come in patterns of one or two strokes)
    Thereby getting both of the necessary sounds from a single data set.

    Two problems with that though...
    1) 27Kb doesn't leave much room in 32kb EEPROM for code.
    2) While it sounds fine on the PC, it doesn't play on the propeller.

    I'm going to need sharper tools for converting wav files to something usable.
    Or maybe look at MP3 players.

    But either way, it's going to need more storage space.
    The Propeller Platform from Gangster Gadgets has a micro SD socket already on board, so
    that's the one I'm using now.

    Waveform.JPG

    Why not just desolder the EEPROM and replace it with a much larger EEPROM that is still compatible with the propeller's boot logic? ... or put a second EEPROM on the same i2c pins as the 'boot' EEPROM?

    An EEPROM is a whole lot cheaper than an SD card and socket.
Sign In or Register to comment.