Shop OBEX P1 Docs P2 Docs Learn Events
12-bit audio using video generator - first working concept — Parallax Forums

12-bit audio using video generator - first working concept

pik33pik33 Posts: 2,393
edited 2012-07-13 06:00 in Propeller 1
Seems to work, so I added a topic for it.

This is version 0.02. Mono, 12bit - it don't have this "duty dac" noise so it doesn't need dithering

But - it seems to generate something at high frequencies (alias?) - I don't hear this, I see it on my equalizer display... need to test it with oscilloscope.

To do:

(1) Stereo should be possible, so do it.
(2) Test what can be possible if reducing it to 9 bit, 4x oversampling and noise shaping
«1

Comments

  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-05 10:08
    After changing
    sample: "sample4"
    To
    sample: "videowav002"
    It works!
    It kind of feels wrong to listen to sample playback through the video generator though. It really shows how dynamic the Propeller is.

    Cool uses of the video generator includes:

    * Mica Dowty used the video generator for s/pdif
    * I have an unreleased SPI driver (a couple of years old know) that uses the video generator to drive both clock and data at the same time at 20 Mbit/sec. A lot of parallel crunching is done while the video generator is busy feeding a byte.
    * If I remember correctly someone wrote a high bandwidth prop to prop communication object that used the video generator
  • pik33pik33 Posts: 2,393
    edited 2012-07-05 10:44
    Corrected.

    Video generator allows to use pll instead of main clock as a conversion base. Up to something about 220 MHz instead of 80 MHz. And this code is really small...
  • groggorygroggory Posts: 205
    edited 2012-07-05 10:56
    That is very clever and looks spectacular.

    How's it sound?
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-05 11:02
    I understand how it works now. That's one of the most clever tricks I have seen on the Propeller! :)
    Keep up the good work!!
  • groggorygroggory Posts: 205
    edited 2012-07-05 11:12
    Could you explain what the exact functions are of the left, right, dither please?
  • pik33pik33 Posts: 2,393
    edited 2012-07-05 11:21
    This version don't dither, these rests of comments and variables are from dithering driver. It is mono now, so it adds left to right and shr it 1 bit. Stereo should be possible, I have an idea how to do it, but it has to be done. Need some time and fresh head.
  • groggorygroggory Posts: 205
    edited 2012-07-05 11:29
    pik33 wrote: »
    This version don't dither, these rests of comments and variables are from dithering driver. It is mono now, so it adds left to right and shr it 1 bit. Stereo should be possible, I have an idea how to do it, but it has to be done. Need some time and fresh head.

    I was just going by what you posted:

    From videowav_demo.spin
    sample: "videowav002"
    .
    .
    .
    sample.start(11,10,7)
    

    and from videowav002.spin
    PUB start(left, right, ditherlevel)
    

    So in videowav_demo.spin, why did you pass the start method for the videowav object (11,10,7) ?
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-05 11:32
    This is TRUE 12 bit pulse width modulation running at ~50 kHz. This will open up some none audio related possibilities as well.
  • groggorygroggory Posts: 205
    edited 2012-07-05 11:43
    Ahle2 wrote: »
    This is TRUE 12 bit pulse width modulation running at ~50 kHz. This will open up some none audio related possibilities as well.

    You know what would be neat...

    Use a specially formulated wav file fed into this driver and the appropriate post DAC circuitry to turn this into an arbitrary waveform generator :-)

    ...

    I still don't understand why in the sample code this line was used:
    sample.start(11,10,7)
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-05 11:46
    For audio use you will need to have a very very very steep filter at around 20 kHz to get rid of the 50 kHz base frequency!
    In that respect duty DAC is better, but this technique will give higher resolution.
  • pik33pik33 Posts: 2,393
    edited 2012-07-05 11:56
    I still don't understand why in the sample code this line was used:
    sample.start(11,10,7)

    "7" is unused. The demo procedure and init procedure are copied from dithering driver I made for my Propeller media player, using Kye's dithering procedure, and it needed dither amount variable. I need to rewrite headers :) You can delete third variable both in call and in procedure header, it does nothing now.
  • pik33pik33 Posts: 2,393
    edited 2012-07-05 11:58
    Ahle2 wrote: »
    For audio use you will need to have a very very very steep filter at around 20 kHz to get rid of the 50 kHz base frequency!
    In that respect duty DAC is better, but this technique will give higher resolution.

    Now we can try lower resoluton with oversampling and noise shaping.
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-05 12:11
    Using this technique in combination with 4 additional pins will give TRUE 16 bit resolution!

    * 4 pins will output the 4 MSBs through a R2R DAC.
    * 1 pin will be used to PWM the 12 LSBs
    * The PWM pin will have to have a signal level of half the R2R DACs LSB. Then simply add the two signals (R2R DAC + PWM) to form the 16 bit signal.
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-05 12:25
    R2R_and_PWM.png

    .............
    569 x 647 - 15K
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2012-07-05 13:36
    The 16 bits will be very useful, I just wish that I could justify worrying over the 20KHz stuff. My ears are so poor that the original demoboard's filters are not "too" bad, what with the tinitus... and the voices...
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-07-05 19:04
    pik33: Seems you have found another great alternate use for the VGA circuitry. Great because we have 8 of these circuits ;)
  • Mark_TMark_T Posts: 1,981
    edited 2012-07-05 19:55
    Ahle2 wrote: »
    For audio use you will need to have a very very very steep filter at around 20 kHz to get rid of the 50 kHz base frequency!
    In that respect duty DAC is better, but this technique will give higher resolution.

    Simple LC filter will do, the speaker and human ear filter out ultrasonics very effectively. The PWM waveform is ready for class D amplifier (another advantage over duty-mode counter)

    Since 12 bit isn't true HiFi it needs sigma-delta conversion with noise shaping filter- this should produce very good sound. However you do, I believe, need to make the PWM phase-correct for this to work well - haven't delved into the code enough to see if this is the case. Put another way I've done 8 bit PWM with a counter and it sounds fantastic with sigma-delta added, 12 bit ought to be at least as good!

    You might then want to try 11 bit at 100kHz as it should be even better as the noise-shaping will perform better with more oversampling. [ and make filtering easier ]
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-06 01:31
    "The PWM waveform is ready for class D amplifier"
    That has been on my todo list for a very long time. I might try this with the Propeller! :)

    "
    Simple LC filter will do, the speaker and human ear filter out ultrasonics very effectively"
    Of course, but the problem isn't the speaker or the human hearing. The amplifier might take a hit (yes, I know about internal low pass filter and bandwidth issues... but still... it might)


  • pik33pik33 Posts: 2,393
    edited 2012-07-06 01:43
    Ahle2 wrote: »
    The amplifier might take a hit



    Tweeters can be burned if the amplifier has sufficient bandwidth.
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-06 02:54
    @pik33
    Yes, that too!
  • pik33pik33 Posts: 2,393
    edited 2012-07-06 02:57
    Bug detected !!!

    If sample value is big, then last waitvid is too short to fit next sample getting procedure. It causes distortions. (listen to 200 Hz sample)
                            mov     vscl,t1
    p11                     waitvid zero,zero
    
                            mov     vscl,vscl_val
                            waitvid ff00ff00,t4
    
                            mov     vscl,t2
    p12                     waitvid ffffffff,ffffffff
    
                            mov vscl,vscl_val2    ' give some time to get next sample value 
                            waitvid ffffffff,ffffffff
    
    (...)
    
    vscl_val2  long $00001200
    (...)
    frqa_val   long $29350000   ' this have to be higher now to do 44 kHz
    
    
  • jmgjmg Posts: 15,176
    edited 2012-07-06 03:07
    Could this use the Video to also generate a clock, and so drive a i2s DAC, which come cheap in 24 bit ?
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-06 03:10
    @jmp
    I might be able to tweek my video-generator-SPI-driver to do that!
  • pik33pik33 Posts: 2,393
    edited 2012-07-06 03:11
    The challenge is: to get "full hifi" (noise in accoustic band < -90dB) out of propeller without adding a dac :)
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2012-07-06 03:27
    For many years the BBC used a single video circuit to distrubute the Band II audio around the UK. The individual elements of that stream was only 13 bits per channel and in the monitoring room you could just detect the granularity of that. As soon as it got shoved through a TX and RX those edges were long gone.
  • Mark_TMark_T Posts: 1,981
    edited 2012-07-06 03:55
    Ahle2 wrote: »
    "The PWM waveform is ready for class D amplifier"
    That has been on my todo list for a very long time. I might try this with the Propeller! :)

    "
    Simple LC filter will do, the speaker and human ear filter out ultrasonics very effectively"
    Of course, but the problem isn't the speaker or the human hearing. The amplifier might take a hit (yes, I know about internal low pass filter and bandwidth issues... but still... it might)



    If the amplifier is class D you don't filter until after the amp - the issue is suppressing EMI enough and preventing power wastage.
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-07-06 04:23
    I was talking about "normal" amplifiers, class A, B, A/B, when I said "The amplifier might take a hit"!
    Of course, I still want to do some thinkering with class D someday.
  • pik33pik33 Posts: 2,393
    edited 2012-07-06 04:41
    0.03 - waitvid bug fixed; now it plays much more clear sound...

    I think it now plays better quality sound than duty dac with dither. Only problem: it is mono now.

    Stereo will need more complex computation and 6 waitvids instead of 4.. there is very small margin for pll left.. now it works @206 MHz...
  • Mark_TMark_T Posts: 1,981
    edited 2012-07-06 07:35
    jmg wrote: »
    Could this use the Video to also generate a clock, and so drive a i2s DAC, which come cheap in 24 bit ?

    Though there's no particular difficulty using counters for I2S clocks, something like sysclk/8, sysclk/32 from counters and LR clock can be done is software. I use a 6.144MHz crystal to get 48kHz sample rate, slightly overclocking the prop, though that's not required. I can adjust the volume and bass and treble in the spare cycles even (using state-variable filtering and unrolled multiply loops!).

    Wolfson Micro do a variety of very cheap 16/24 sigma-delta DACs and ADCs for I2S bus, WM8783, WM8524, WM8759 are the ones I've used, WM8782 is next on the list to play with. Very easy to interface to with the Prop due to the deterministic timing and multiple counters.
  • jmgjmg Posts: 15,176
    edited 2012-07-06 15:07
    pik33 wrote: »
    The challenge is: to get "full hifi" (noise in accoustic band < -90dB) out of propeller without adding a dac :)

    Of course, but a version that DOES use a i2s DAC, allows you to compare how you are going... target the best of both choices.
Sign In or Register to comment.