Author Topic: Methods For Playback of Waveform Audio  (Read 4896 times)

0 Members and 1 Guest are viewing this topic.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Methods For Playback of Waveform Audio
« on: December 22, 2013, 04:49:55 pm »
With the recent improvements in video compression I have made, it appears that I will have 500-550KB of space in Bad Apple which I can use for audio, which works out to 18kbits/s. Because of this, I want to try playing back waveform audio of the original song, rather than synthesized notes. What are the pros and cons of different methods used to play back 8 bit audio on 1 bit outputs used by other sound applications like RealSound and TruSound? I haven't found much information about how they work. I also found this algorithm, which encodes higher bit audio down to 1 bit by predicting the behavior of an RC filter, so how does it compare?

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Methods For Playback of Waveform Audio
« Reply #1 on: December 22, 2013, 07:35:45 pm »
I've explained this many times before. I don't remember where and I don't feel like finding it, but there's a really good explanation out there somewhere. Probably in either the trusound or truvid threads.

The basic idea is that you need to use pulse width modulation to approximate different voltages. You're going to be flipping the link port 18,000 times per second. This means you're going to send 18,000 groups of ON OFF. Now, the timing of your ON OFF determines the approximate voltage. 50% ON 50% OFF is of course the middle voltage. 0 100, 33 67, 67 33, 100 0 gets you 2 bits of output with 4 possible positions. The more voltages you have the better it's going to sound obviously. I think in trusound I used something like 250 steps.

To finally play your music, just run through the data and output the correctly timed ON and OFF pulses. The main downside to this is that depending on how you implement it, it takes 30%-100% of the cpu power just to play music.

zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Methods For Playback of Waveform Audio
« Reply #2 on: December 22, 2013, 08:32:17 pm »
Yup, you'll want to use PWM.

When the port is ON during 1/88200 of a second, it's a 1 and when it's OFF it's a 0. Repeat in groups of 8 bits 11025 groups a second, convert your WAV to 11025 Hz, send the data down the link port in PWM and I think you'll get a decent rate.

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Methods For Playback of Waveform Audio
« Reply #3 on: December 22, 2013, 08:57:19 pm »
You can use pwm or you could use external hardware like a digital to analog converter with a 2 wire interface.
« Last Edit: December 22, 2013, 08:58:19 pm by Keoni29 »
If you like my work: why not give me an internet?








Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Methods For Playback of Waveform Audio
« Reply #4 on: December 22, 2013, 09:15:43 pm »
You can use pwm or you could use external hardware like a digital to analog converter with a 2 wire interface.
Most people will want to plug their headphones directly in the calc with a 2.5mm to 3.5mm converter or using an AM radio.

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Lunar Fire

  • LV3 Member (Next: 100)
  • ***
  • Posts: 66
  • Rating: +7/-1
  • I'll be watching you from the shadows
    • View Profile
    • My Tumblr
Re: Methods For Playback of Waveform Audio
« Reply #5 on: December 22, 2013, 10:21:07 pm »
You have to see with the remaining program space you can use and the available processing power to determine at which rate you can play the audio. I honestly don't believe you will be able to play audio at 18 khZ, but this seems to be a starting point. You can lower the quality after if it slows down your program.

If I looked at your timing loop well, once it is done rendering a frame it waits for your 1/30th second to render the next. You will have to change your timing loop for it to process your waveform audio before waiting for the next frame. Basically here your goal will be to calculate your image and audio generation loops to have as few waiting time as possible between frames.
Your drill is the drill that will pierce the heavens!

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Methods For Playback of Waveform Audio
« Reply #6 on: December 22, 2013, 10:53:27 pm »
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?
« Last Edit: December 22, 2013, 10:57:48 pm by fb39ca4 »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Methods For Playback of Waveform Audio
« Reply #7 on: December 23, 2013, 01:38:05 pm »
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?
Yes and yes. I would actually recommend using two crystal timer interrupts to do the audio output, the first repeating at the sample rate and the second scheduled by the first. As for the noise problem... I'm not sure exactly what you should do about that. I guess increasing the sample rate would be out of the question. (Well actually, you could perhaps reduce the audio quality to 6-bit or something, there's really a limit as to how accurate your PWM timing can be anyway)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Methods For Playback of Waveform Audio
« Reply #8 on: December 23, 2013, 09:50:23 pm »
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?

From my experience, 18KHz is about the minimum frequency you can use and not be able to hear it. If I moved my head around, I could hear doppler effects, but sitting still it sounded fine. I was 18 when I decided this, so take that as a reference because the younger you are, the higher the frequency you can hear. If you use 20KHz, you should be safe with all age groups.

Edit:
   Also, what really sucks when you start doing sound is that you find out that not all calculators run at the same clock rate. Your range is basically 14.5MHz - 17.0MHz
« Last Edit: December 23, 2013, 09:51:11 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Methods For Playback of Waveform Audio
« Reply #9 on: December 24, 2013, 05:46:25 am »
By using a simple audio filter you can filter out anything above a certain frequency.
If you like my work: why not give me an internet?








Offline Lunar Fire

  • LV3 Member (Next: 100)
  • ***
  • Posts: 66
  • Rating: +7/-1
  • I'll be watching you from the shadows
    • View Profile
    • My Tumblr
Re: Methods For Playback of Waveform Audio
« Reply #10 on: December 26, 2013, 11:34:06 pm »
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?

From my experience, 18KHz is about the minimum frequency you can use and not be able to hear it. If I moved my head around, I could hear doppler effects, but sitting still it sounded fine. I was 18 when I decided this, so take that as a reference because the younger you are, the higher the frequency you can hear. If you use 20KHz, you should be safe with all age groups.

Edit:
   Also, what really sucks when you start doing sound is that you find out that not all calculators run at the same clock rate. Your range is basically 14.5MHz - 17.0MHz

From what I learned in my classes, we can hear audio at frequencies from around 20Hz to 20 kHz. That's why audio is most of the time sampled at 44kHz (avoids aliasing). Around 18kHz will probably be fine for you. You might have a few audio glitches but anything under 44kHz will. As for the actual method of implementing it, I can't really help you. Sorry.
Your drill is the drill that will pierce the heavens!