Shop OBEX P1 Docs P2 Docs Learn Events
reSound - A sound driver and mixer for the P2 — Parallax Forums

reSound - A sound driver and mixer for the P2

Ahle2Ahle2 Posts: 1,179
edited 2020-05-20 11:00 in Propeller 2
reSound Beta 1

Features:
* Runs in a single cog
* Can mix arbitrary number of input channels (up to 64 atm) into any of the up to 8 output pins
* Can be used to generate surround sound on up to 8 speakers
* Each input can have arbitrary sample frequency and bit depth (example, mix 16 bit CD quality @44100Hz with 8 bit samples from an old school game @12345Hz)
* Each input can use its own sample format: 8 bit signed/unsigned, 16 bit signed/unsigned, little/big endianness
* Can be used to play back single shot samples
* Can be used as a sound buffer with interrupt handling (like in modern operating systems)
* Can be used for continuous waveform playback of any size, bit depth, frequency, volume and mixed arbitrarily into any of the outputs
* Can use any combination of the three points above on the different input channels (example, CD audio quality playback + waveforms + singleshots = game sound engine)
* All parameters can be changed on the fly, frequency, volume, panning, loop size.. etc (the included trackerPlayer example depends on this)
* Different built in sound processing options can be applied, like multimode resonance filter, reverb, distortion... etc (very rudimentary atm)
* This list will grow and change over time.

A link to all the music modules used in the example: https://gofile.io/d/1ZSNg9
A link to a free HiFi tune in wav format to use in the wav playback examples: https://gofile.io/d/5tN9D8

Original first post below...
Hello folks,

Here comes an alfa preview of my upcoming sound driver for the P2. It includes two examples of usage as well. :)

Features:
* Runs in a single cog
* Can mix arbitrary number of input channels (until the cog chokes) into any of the output pins
* Can output on up to 8 smart pins for surround sound
* Each input can have arbitrary sample frequency and bit depth (example, mix 16 bit CD quality @44100Hz with 8 bit samples from an old school game @12345Hz)
* Each input can use its own sample format: 8 bit signed/unsigned, 16 bit signed/unsigned, little/big endianness
* Can be used to play back single shot samples
* Can be used as a sound buffer with interrupt handling (like in modern operating systems)
* Can be used for continuous waveform playback of any size, bit depth, frequency, volume and mixed arbitrarily into any of the outputs
* Can use any combination of the three points above on any input channel (example, CD audio quality playback + waveforms + singleshots = game sound engine)
* All parameters can be changed on the fly, frequency, volume, panning, loop size.. etc (the included trackerPlayer example depends on this)
* This list will grow and change over time..

Performance:
* At the moment it can mix 58 sixten bit input channels @44100 Hz in stereo mode on a P2 running @250 MHz

Fun times ahead! :)


/Johannes
«134

Comments

  • cgraceycgracey Posts: 14,153
    Super, Johannes!

    Tell me, what is the analog output audio quality like? Is it noticeably lower than normal audio gear?

    Are you using the 16-bit DAC LSB-PWM-dithering smart pin mode? At 123 ohms? Are you using the pull-down resistor for 2.0V output?
  • Hello Johannes, that sounds really interesting. And is probably exactly where I want to go. But how am I supposed to use that, I'm hanging light years away. I guess I need an SD card? Should I then load the unzipped files onto the card?
    Can you give something like a guide for dummies.
    Kind regards, Reinhard.
  • Ahle2Ahle2 Posts: 1,179
    > @cgracey said:
    > Super, Johannes!
    >
    > Tell me, what is the analog output audio quality like? Is it noticeably lower than normal audio gear?
    >
    > Are you using the 16-bit DAC LSB-PWM-dithering smart pin mode? At 123 ohms? Are you using the pull-down resistor for 2.0V output?

    Default mode is 16- bit DAC LSB-NOISE mode in 2V/123ohm. The driver chooses the better sounding PWM mode if the system clock is a multiple of the wanted mixing frequency.

    The P2 noise floor is quite low (better than 80dB it seems, but I haven't done real measurements yet) and the over all audio quality is quite good according to my ears. Waaaay better than the P1. I Will try to get real measurements.
  • cgraceycgracey Posts: 14,153
    edited 2020-01-31 18:17
    Johannes, I was just curious about your subjective experience. I'm happy to hear it sounds good! It may be fine to always use the PWM-dither mode, since there will be maybe a dozen full cycles before a sample change. The noise-dither mode is a lot noisier. Let your ears be the judge.
  • Ahle2Ahle2 Posts: 1,179
    > @Reinhard said:
    > Hello Johannes, that sounds really interesting. And is probably exactly where I want to go. But how am I supposed to use that, I'm hanging light years away. I guess I need an SD card? Should I then load the unzipped files onto the card?
    > Can you give something like a guide for dummies.
    > Kind regards, Reinhard.

    Compile "main.spin2" using fastspin in any of the example folders. Change left and right pin definitions to suite your needs. In the tracker example, you could uncomment the tune you want to play back. There is no example of playing waveforms or playing stereo wav files from SD card in the examples above. That should be easy though, my first examples focused more on realtime mixing and playing samples with frequency control and the mixing capabilities of the driver. For simple stereo playback from SD you might not even need a driver, just an interrupt routine and a double buffer.
  • Is it possible to do sound bits and regular words, each recorded separately and stored in memory or SD card, and then played back in a programmed sequence to make up a sentence?
  • Ahle2Ahle2 Posts: 1,179
    PropGuy2,

    Each word is a sample in memory... then you just need to piece them together with a little delay. You could easily modify the drum beat example to do this.
  • This is really exciting! Thank you. Now it is hard to finish work... lol
  • Ahle2 wrote: »
    * Can output on up to 8 smart pins for surround sound

    Have you thought of implementing surround matrixing? That's probably more commonly supported/useful than discrete surround channels.
    Although doing it properly would require applying a phase shift to the surround channels. I don't even have a clue of how that would work...
  • I got it to work on my setup!
    Is there a volume control anywhere on the A/V board setup?
  • This all looks great Ahle2, can't wait to try it out later. :smile:

    Do you also see a future for audio input sources read from external memory at some later time? Perhaps with your mixing architecture being developed one day it may also enable playback of much larger samples stored in a larger HyperRAM/HyperFlash memory? I am still hoping that we might be able to do that one day and share this memory interface with video access too. Of course there will be latency and jitter introduced into these audio accesses when it is shared with video, and video will need to get priority in its transfers to avoid screen corruption. I'm hoping that intermediate transfer buffers will help audio reach performance levels required, so we don't have to generate new access requests on every single sample for example (which is unlikely to end well), and find a way where we can transfer larger blocks more efficiently. Of course there will be some limits to the number of simultaneous channels etc, but I'm thinking something could be possible there.
  • Mods demos worked! Funny how listening to music like this floods your mind with happy thoughts of a fun time of life gone by. Games and demos of the 90s. What a time!

    Couldn't get the other resound sample demo to work. I am using the A/V board outputting left/right on pins 6/7, and I patched the pins accordingly in main.spin2 of this demo but it didn't seem to work. Probed these pins with my scope, saw no output. Also tried on pins 0,1 which was the original default in the code, still no sound/scope output from this demo. Were only pins 0 and 1 meant to work for this one? Has anyone else got the drum demo working? Mod demo was fine.
  • cgraceycgracey Posts: 14,153
    Ha, I got this running with FlexGUI. Really neat!

    It seems in the sample player that the kick drum is not working.

    I see you've got the meat hidden in a binary.

    Are you using the CORDIC to do any processing?

    Is the music compressed or are you synthesizing it? It seems like it's compressed.
  • roglohrogloh Posts: 5,787
    edited 2020-02-01 00:51
    @cgracey Did you use the A/V board and which pins did you use with main.spin2 for the drum demo Chip? I have Flexgui too (older 4.0.4 fastspin) but it doesn't work for me, only the mod player demo worked which is confusing.

    Update: I do have the HyperRAM board fitted on pins32.39 which I guess I should yank out in case that is somehow affecting things with this audio demo.
  • cgraceycgracey Posts: 14,153
    Rogloh, I used the A/V board and pins 6 and 7 for output, which seem to be the headphones (not sure, but 5 and 6 also worked).

    I'm using FlexGUI 4.1.0.
  • Weird, it still doesn't output on 0/1, 5/6, 6/7, and I yanked my HyperRAM and that didn't help. It must be related to the flexgui / fastspin version difference, I can't think of anything else. Volume was cranked up fully and nothing. The P2+A/V board is able to output audio on pins 6/7 fine with the other mod file player demo.

    I do get a warning when I build this too though it also showed up for the mod player demo which does work..
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.4-beta- Compiled on: Nov 16 2019
    /Users/roger/Downloads/reSoundAlfaExamples/Ahle2_reSoundSamplePlayback/reSound.spin2:119: warning: Label is dereferenced with greater alignment than it was declared with
    main.spin2
    |-reSound.spin2
    main.p2asm
    Done.
    
    This is line 119 with the warning:

    long[@RESOUND][149] := hubRegPtr
  • cgraceycgracey Posts: 14,153
    It only takes a few seconds to download the latest FlexGUI.
  • Yes I know I should go do that, but it took a while to setup things right on the Mac with my various customizations etc so I will need a bit longer to port that over to set it up again...I'm in the middle of the HyperRAM coding stuff right now and am discouraged from changing things right now while the tools are (mostly) working.

    I find that changing/updating tools is generally a distraction for me and there is too often scope for failure...
  • Really great example of what P2 can do!

    Both modules & sample versions working as compiled with fastspin -v 4.1.1 (same as in flexgui v 4.1.1), for pins 6 & 7.
    And, I'm getting the kick drum, without issue. The BassU8 sample works as well. Not as much luck with TrumpetS8, but that could be my choice of frequencies.

    dgately
  • roglohrogloh Posts: 5,787
    edited 2020-02-01 03:33
    Ok, so I downloaded the latest 4.1.0 spin2cpp and built it for the Mac. I copied the binary to flexgui/bin folder (and saved my original). So at least I can try to make the demos now with the newer spin compiler (I noticed those warnings went away). I still kept the same older flexgui with all my customisations but that's just the UI. Again with the new compiler the mod file demo works, but the drum demo doesn't. I'm starting to think it might be my older loadp2 tool is somehow causing the issue. I'll have to update that too when I can. Still doesn't really make sense if all the other code I download with it seems to work though...
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2020 Total Spectrum Software Inc.
    Version 4.1.0 Compiled on: Feb  1 2020
    main.spin2
    |-reSound.spin2
    main.p2asm
    Done.
    Program size is 273792 bytes
    Finished at Sat Feb  1 14:13:48 2020
    /Users/roger/Downloads/flexgui-4.0.3/myscript  -p /dev/cu.usbserial-P23YOO36 /Users/roger/Downloads/reSoundAlfaExamples/Ahle2_reSoundSamplePlayback/main.binary /Users/roger/Downloads/flexgui-4.0.3  
    
  • That's really cool, and sounds great. I am hoping that Chip will write a multi-file SD file reader that can be used to feed this. For lots of projects I need a background track with effects mixed in and played over it as needed.
  • Ahle2Ahle2 Posts: 1,179
    > @cgracey said:
    > Ha, I got this running with FlexGUI. Really neat!
    >
    > It seems in the sample player that the kick drum is not working.
    >
    > I see you've got the meat hidden in a binary.
    >
    > Are you using the CORDIC to do any processing?
    >
    > Is the music compressed or are you synthesizing it? It seems like it's compressed.

    The CORDIC is not used in any form at the moment. I have a lot of possible skip patterns to fill up, maybe some COORDIC operations will fit in there and be used for different FXs?!

    The music is from the Amiga days and is completely sample based. No synthesis or compression at all. Just playing different 8 bit samples with realtime (50 Hz) control of pitch and volume into 4 audio channels. The note data, effects and samples are all in the same file, hence the name, "module". The cool thing is that the Amiga did all this in hardware in 1985 with 4 separate DACs that each could output arbitrary pitch and volume. No mixing involved.
  • Ahle2Ahle2 Posts: 1,179
    Here is a clip from a module tracker editor running on the Amiga. You can visually see what's going on. Each note scrolls into position and triggers a sample with some pitch and volume. The numbers beside each track are effects like pitchbend, portamento, vibrato, tremolo and other things. These effects gets updated at 50 Hz on a PAL Amiga (which is the default because the Amiga was a big hit outside the states)

  • Ahle2Ahle2 Posts: 1,179
    I Will try to figure out what's wrong with the drum beat example. It's works for me! It may have something to do with my hacky way of setting the hub pointer reference with an offset into the reSound binary! That's the warning you saw rogloh!
  • This is such a great piece! Thanks for linking it here. I've not heard it in a long while.

    Still good.

    It hits on all the notes. Technical use of the 4 channels, musical form, instrumentation, it all fits into a high energy package that leaves a person wanting more.

    Hey, maybe we will see a music scene on P2. (let's hope)

  • Ahle2Ahle2 Posts: 1,179
    Try to long align the reSound binary data.
  • Ahle2Ahle2 Posts: 1,179
    > @rogloh said:
    > This all looks great Ahle2, can't wait to try it out later. :smile:
    >
    > Do you also see a future for audio input sources read from external memory at some later time? Perhaps with your mixing architecture being developed one day it may also enable playback of much larger samples stored in a larger HyperRAM/HyperFlash memory? I am still hoping that we might be able to do that one day and share this memory interface with video access too. Of course there will be latency and jitter introduced into these audio accesses when it is shared with video, and video will need to get priority in its transfers to avoid screen corruption. I'm hoping that intermediate transfer buffers will help audio reach performance levels required, so we don't have to generate new access requests on every single sample for example (which is unlikely to end well), and find a way where we can transfer larger blocks more efficiently. Of course there will be some limits to the number of simultaneous channels etc, but I'm thinking something could be possible there.

    I will look into this at some point. I don't have any experience with hyper RAM though. I willl also look into I2S and spdif.
  • This is a fantastic demo. I had no problem with compiling and downloading. Is the reSound.binary also written in spin or is this pasm ?
    f I understand the pasm listing correctly, 5 cogs are still idle ;-)

    best regards, Reinhard
  • Ahle2 wrote: »
    I will look into this at some point. I don't have any experience with hyper RAM though. I willl also look into I2S and spdif.
    No worries. We'll soon have a HyperRAM driver that will be able to read any audio data from HyperRAM at the same time as video is using it by making simple hub memory mailbox requests. I'm still testing it out. The main issue is that in this configuration the external memory won't like lots of individual random accesses (you may only get a few opportunities to access it per video scan line if video is also using it for example), so you would need to make good use of larger read bursts for best performance. How well that can work out in a tracker or mixer application that is reading from lots of different memory locations I'm not sure. It will best be done by locating the frequently accessed structures in hub RAM I would expect or by caching result where possible if the data being accessed is sequential. Also if no video regions are using external memory there will be more opportunities for doing audio transfers from this memory.

    Having I2S would be great and should be somewhat easier to output compared to SPDIF encoding. With any luck hopefully it also fits within your same mixer COG with some smartpin modes and/or possibly using the streamer to avoid the extra COG(s).

    I still really don't know what is wrong in my setup with your reSound drumbeat demo now that I'm using fastspin 4.1.0 to build it. I'll have another go at it tomorrow when I'm more awake. However your mod file tracker demo worked well for me. Good stuff @Ahle2!
  • Ahle2Ahle2 Posts: 1,179
    > @Reinhard said:
    > This is a fantastic demo. I had no problem with compiling and downloading. Is the reSound.binary also written in spin or is this pasm ?
    > f I understand the pasm listing correctly, 5 cogs are still idle ;-)
    >
    > best regards, Reinhard

    Thanks Reinhard!

    It's written in pasm for speed.. I will release the source when it's in better shape!
    6 cogs are idle actually. The tracker object code runs in the main cog!
Sign In or Register to comment.