1 bit audio

stan74

Senior Member
It's too late to try this. Has anyone? I'll try tomorrow and if it works when I find a speaker try using a bit not a byte.
Code:
[color=Green]; 1 bit audio record and playback from 8ohm speaker[/color]
[color=Navy]#picaxe [/color][color=Black]28x2[/color]
[color=Blue]setfreq m16[/color]
[color=Black]main:[/color]
[color=Blue]wait [/color][color=Navy]5[/color]
[color=Blue]for [/color][color=Purple]ptr[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]1023 [/color][color=Green];record
      [/color][color=Purple]@ptr[/color][color=DarkCyan]=[/color][color=Purple]pina.0[/color]
[color=Blue]next [/color][color=Purple]ptr[/color]
[color=Blue]wait [/color][color=Navy]5[/color]
[color=Blue]for [/color][color=Purple]ptr[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]1023 [/color][color=Green];playback
      [/color][color=Purple]pina.0[/color][color=DarkCyan]=[/color][color=Purple]@ptr[/color]
[color=Blue]next [/color][color=Purple]ptr[/color]
[color=Blue]goto [/color][color=Black]main[/color]
 

stan74

Senior Member
I tried it on a zx81 once and speech is understandable but no rc. May need headphone out to record or see what inputtype does and use a rotating mask ored onto ptr to use bits but might be too slow. I'll see later.
 

hippy

Technical Support
Staff member
I tried it once, converted a WAV file to a scratchpad image and blatted that out. I can't fully recall what the results were like and not sure if I wrote about that on the forum. If remembering correctly it sort of worked but not very well, but it was just to a piezo hung on an IO pin.

With cheap high quality players like the AXE171+SPE035 audio player, bit-banged sound is more novelty than useful.
 

inglewoodpete

Senior Member
With the correct hardware (comparator and 2 x integrator) and fast sampling, the quality of sound from a 1-bit wide delay line can be quite acceptable - almost hi-fi with fast enough sampling. The fast sampling is required to cope with the high slew rate required for high (audible) frequencies. A bare PIC or (gasp) PICAXE is not going to do the job on its own.

This electronic design article explains how it is done.
 

Rick100

Senior Member
Hello Stan,

If you want to collect 1 bit samples at a higher rate with a Picaxe, you might be interested in a project I started last year with a 23lc1024(128K bytes) spi serial ram chip and an 18M2. I was using it to sample the output of an IR receiver. The sample rate was 40KHz but could have been higher. The method I used was bit banging the spi to set up the continuous write mode and address, and then turning on PWM to drive the clock line. The output of the IR receiver drove the data line of the serial ram. A pause to set the sample time and then turn off the PWM. The DSM was used to route the IR receiver output into the serial ram data input line to avoid an external gate. The plan was to record and then play back the signal for a teachable remote. I got the recording part done but lost interest and never finished it. The 23lc1024 is interesting because it has SDI and SQI modes which would allow it to read in 2 or 4 bits in parallel. I thought another interesting project would be to make a simple logic analyzer using the OLS PC software. I tried getting the Picaxe to communicate with the OLS software but was unsuccessful. I think this logic analyzer uses the same technique.
http://dangerousprototypes.com/docs/Logic_Shrimp_design_overview

Of course the problem with a 128K eeprom hooked to a Picaxe is how to you process the data. If your interested, I can clean up the code and post it.

Roman Black had a long thing about 1 bit audio some years ago - there were some demo files etc... 1023 bytes won't give you much to work with! http://romanblack.com/ - I looked to see if it was still there ...http://romanblack.com/picsound.htm
I tried Roman Blacks code several years ago on a 12f675 with an i2c eeprom. The sound quality was poor with high frequency noise. I was trying to make the chuff, whistle, and bell sounds for a garden railway engine. I ended up using the pwm output of a 12f683 with a wav file stored in the eeprom. The i2c was bit banged, which limited the sample rate to 8K . The sound quality was decent.

Good luck,
Rick
 

edmunds

Senior Member
Could not find it sooner, but here it is - a discussion some time ago, where I tried to build one. I think I got some sort of sound out of it, but not anything you could refer to as music :D.

Edmunds

EDIT: But then @Rick100 did a pretty cool implementation actually. Page 5 of the thread or so.
 

stan74

Senior Member
It was too short. 1k of 1's and 0's. I got "hello" with a zx81 which was 6.5 MHz and 6K available ram, through the cassette mic socket. I suppose it could be compressed by counting 0's and 1's. You could do r2d2 with pwm.
 

Rick100

Senior Member
With the correct hardware (comparator and 2 x integrator) and fast sampling, the quality of sound from a 1-bit wide delay line can be quite acceptable - almost hi-fi with fast enough sampling. The fast sampling is required to cope with the high slew rate required for high (audible) frequencies. A bare PIC or (gasp) PICAXE is not going to do the job on its own.

This electronic design article explains how it is done.
I've been playing with the circuit in the link posted by IWP connected to the internal comparator of an 18M2. The bits are clocked into a 23lc1024 serial ram. Here's a video of the result.

https://youtu.be/E_9EddjMXHo

The samples are at 100 KHz with the suggested values for the resistor and capacator from the link. The results are not as good as I would like but it's been fun getting this far. I tried sample rates up to 300 KHz. It sounded a little different but not much better. It's kind of hard to tell whats going on with my old Tektronics 422 scope. It would be very interesting to see the audio input and bit stream from the comparator on a digital scope. An Adafruit electret mic and amp supplied the audio signal. I first tried an LM339 comparator but I don't think it sounded as good as the internal comparator. The article suggest an LM311 as a faster comparator. I might try one of them later on. Does anyone have a suggestion for a better comparator? I'm sure the long wires aren't helping anything.
 

premelec

Senior Member
@Rick100 - that's interesting and sounds like a lot of 'noise' - my question is what does it sound like with NO input - just reading 0 or whatever - is that 'noise' an artifact of the readback glitches and filter?
 

Rick100

Senior Member
@Rick100 - that's interesting and sounds like a lot of 'noise' - my question is what does it sound like with NO input - just reading 0 or whatever - is that 'noise' an artifact of the readback glitches and filter?
Hello premelec,

If I remove the audio signal from from where it enters the AC coupling capacitor, the noise remains. If I double the .01 capacitor labeled RX on the schematic, by putting another .01 cap in parallel, most of the hiss goes away but the audio quality drops. When I was debugging the program with it hooked to the PC, I noticed the terminal window was receiving characters during playback. The output of the comparator is on the same pin as serout. It seems the pwm was causing the comparator to change it's output. I just looked at the output coming from the serial ram chip with an Ebay logic analyzer. The output stream is mostly high with a lot of 6 uS low pulses. I'm not sure where the 6 uS comes from since the clock is 100 KHz. As a sanity check, I used the output of the IR receiver on the AXE091 board as a signal source and looked at that on the logic analyzer. It showed the 9 millisecond lows and the rest of the bit lengths I expected from my TV remote.

Thanks,
Rick
 

premelec

Senior Member
probably try shorter leads and good grounds - what do you see after the RC filter? If 6usec is showing up there that means your filtering isn't working well... it shouldn't show up at all at audio frequencies. Might have to use a sharp cutoff LC filter [eliptic] made to particularly reject your clock frequency. I guess there are active filters [with op amps] that work well though I have no experience with them.
 

Rick100

Senior Member
probably try shorter leads and good grounds - what do you see after the RC filter? If 6usec is showing up there that means your filtering isn't working well... it shouldn't show up at all at audio frequencies. Might have to use a sharp cutoff LC filter [eliptic] made to particularly reject your clock frequency. I guess there are active filters [with op amps] that work well though I have no experience with them.
Hello premelec,

When I work on it again, I may try try rebuilding it on another bread board instead of the AXE091 board so I can shorten the wires. My old analog scope doesn't show much that I can interpret after the filter. I would like to have a decent digital scope but they are outside my price range. The PC based ones like the Hantek HT6022BE are affordable but I'm not sure how useful they are. The next time I order some parts, I will get some LM311's. The project is only for fun and I've learned a lot so far. Stan74's original post reminded me of a type in program for a C64 many years ago. It recorded from an audio cassette played in the Datasette tape drive. The recorded sound played back by the C64 was even worse than my Picaxe circuit.

Thanks,
Rick
 

stan74

Senior Member
I looked up sampling noise and got nowhere, conflicting views,hard sums,orders of harmonics etc.
1 bit sampling can, it seems be very good.
PWM tones are good if you mix 2 with a 28x2.
At the moment I'm using b.0 and b.5 and rc connected to scope channels in x/y mode but the scope crashes in x/w mode.
Going to try it with winscope.
Code:
main:
pwmduty b.0,0:pwmduty b.5,0 
pwmduty b.0,0:pwmduty b.5,399
pwmduty b.0,399:pwmduty b.5,399
pwmduty b.0,399:pwmduty b.5,0
goto main
Draws a square...sort of :)
 
Top