Amen brother ~ 6 bit audio @ 16.3kHz

Basic and Machine Language

Moderator: Moderators

User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by chysn »

At the moment, I've got a (non-VIC) hardware problem preventing me from transferring stuff to my real VIC, but I can't wait to try this.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

chysn wrote: Fri Sep 04, 2020 7:09 am At the moment, I've got a (non-VIC) hardware problem preventing me from transferring stuff to my real VIC, but I can't wait to try this.
Me too. Well, seems to give the regular sound of speakers wrapped up in packs of toilet paper but with less aliasing sound.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by Noizer »

pixel wrote: Fri Sep 04, 2020 6:53 am
Noizer wrote: Fri Sep 04, 2020 4:54 am How can it work with 6bit resolution? Volume register 900E has only 4bits available. Please explain the function
Four pulses for each sample which add up. Doesn't give you 6 bits with 64 values really but more like 61 values. Close enough.
Hello Pixel, OK, then it goes public. 👍
Yes you are right. Targeted feedback was still missing. Didn't have time to finish the comment.
- Why PM? It is possible that I am wrong and that there could have been misunderstandings. Topics don't always have to be littered with OT.
  • So here are my results, suggestions and questions. My programming environment is always the real thing
The sample sounds good, provided that the JSR 7100 boosting is switched off.
The continuous tone for boosting only breaks the sound, it's not worth it.
BTW, please let Tom delete the Youtube video, it sounds really bad and it doesn't show the real quality of the routine.
viewtopic.php?f=1&t=8948#p100144

If I understood correctly, all 4 sections in the code are connected, means four bytes represent a 6 bit sample, right?

I think you can get even more out of the code.
I have created a stripped down version that is not precisely fixed for the cycle, but which averages 25.6 Khz playback frequency. But it still sounds clean. Unfortunately I don't have an adapted sample.

With which wave format did you actually do it?
And how did you convert it? Some script?

Anyway, here a version without boosting and a separate wave file, played by the real machine.
Files.zip
(1.75 MiB) Downloaded 61 times
Greetings, Noizer
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

Noizer wrote: Sun Sep 06, 2020 4:58 am Anyway, here a version without boosting and a separate wave file, played by the real machine.
REAL MACHINE!!!1!1!!! Just let me finish my tenth Sunday beer and zip the original up for you tomorrow morning....

EDIT: Amen, brother
EDIT AGAIN: If I wasn't seeing the DC offset I wouldn't believe crap. Very quiet tho.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

Noizer wrote: Sun Sep 06, 2020 4:58 am With which wave format did you actually do it?
And how did you convert it? Some script?
Had downloaded some Youtube video, extracted the audio as unsigned 8-bit WAV, probably with ffmpeg and them had it go through a lowpass filter with sox to get the frequencies below the Nyquist limit to avoid extra noise. That WAV data then got included as it was, with the 44 byte header cut off and just long enough to form a loop.

Am assuming the the playback frequency is just too high because each sample output will take some time to reach it's peak, making the whole thing far too quiet. If there was a regular VIC tone in that piece you recorded, there'd have been blood. ;) Sounds amazing anyhow. How did it come to that fade-out?

We could find out the maximum frequency that makes sense for the loudest output by reading the VICE source code or grabbing an oscilloscope or by asking Mike. :mrgreen: Easing up on the sample rate is the only way to mix "new frontiers in VIC graphics" with "new frontiers in VIC audio". Isn't that what we all wanna experience? :twisted:

p.s.: I wouldn't bother Tom. And I don't mind if my BS gets documented. Things just evolve. That's how it is and no delete button will change that. Wish I had at least an high school diploma in math...
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

Due to lack of time here's what I've got laying around at the moment. Didn't track any changes though. Was mostly counting cycles like a hen counting it's chicks. ("Two, four, seven... no hang on, four, seven, eleven... na... six... etc.)

Code: Select all

; Play four volumes for each sample value exactly every 17 CPU cycles.                                                                                                                                                                                                                                                                                                                                                          
; On PAL the playback rate is 16.3kHz (1108404 / 17 / 4),
; on NTSC it's 15.1kHz (1027270 / 17 / 4).
; The volumes add up from 1 to 60 which makes almost 6-bit quality.
; 0 is used to mark a sample's end.
fill @(- 256 (mod *pc* 256))

play_6bit_audio:
restart:
    ; Set pointer to start of sample.
    lda #<sample
    sta @(+ 1 +l)
    lda #>sample
    sta @(+ 2 +l)

    ldx #0          ; Index into sample.
l:  ldy sample,x    ; 4 Get sample value.
    beq -restart    ; 2/3 Start over if the sample value is 0.
    lda vals0,y     ; 4 Get first volume register value for this sample.
    sta $900e       ; 4 Set HF carrier volume.

    inx             ; 2 Step to next sample value.
    beq +n          ; 2/3 Step to next page…
    nop             ; 2 (Waste 5 cycles.)
    bit $ea         ; 3
    lda vals1,y     ; 4 Set the second volume for this sample.
    sta $900e       ; 4

    bit $ea         ; 3 (Waste 9 cycles.)
    bit $ea         ; 3
    bit $ea         ; 3
    lda vals2,y     ; 4 Set the third volume for this sample.
    sta $900e       ; 4

    inc $900f       ; 6 Border colour effect.
    bit $ea         ; 3 (Waste 3 cycles.)
    lda vals3,y     ; 4 Set the fourth volume for this sample.
    sta $900e       ; 4

    jmp -l          ; 3

n:  nop             ; 2
    nop             ; 2
    lda vals1,y     ; 4 Set the second volume for this sample.
    sta $900e       ; 4

    inc @(+ 2 -l)   ; 6 Step to next page.
    bit $ea         ; 3
    lda vals2,y     ; 4 Set the third volume for this sample.
    sta $900e       ; 4

    inc $900f       ; 6 Border colour effect.
    bit $ea         ; 3 (Waste 3 cycles.)
    lda vals3,y     ; 4 Set the fourth volume for this sample.
    sta $900e       ; 4

    jmp -l          ; 3

    ; Split up 60 possible sample values into chunks of four 4-bit values
    ; that'll add up when playing.  The chunks are interleaved.
init_6bit_audio:
    ldx #0
l:  txa
    lsr
    lsr
    tay
    jsr mkval
    sta vals0,x
    jsr mkval
    sta vals1,x
    jsr mkval
    sta vals2,x
    jsr mkval
    sta vals3,x
    inx
    bne -l

    rts

mkval:
    tya
    cmp #15
    bcs +l
    ldy #0
    rts
l:  sec
    sbc #15
    tay
    lda #15
r:  rts

    fill @(- 256 (mod *pc* 256))
vals0:  fill 256
vals1:  fill 256
vals2:  fill 256
vals3:  fill 256
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
groepaz
Vic 20 Scientist
Posts: 1187
Joined: Wed Aug 25, 2010 5:30 pm

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by groepaz »

It would be nice to get some recordings from real HW and the programs that were used to produce them (not only for this sample stuff) so i could put them into the test repo. Small dedicated programs that do nothing but play a certain sound that is, games or demos are not very useful as testcases :)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by Noizer »

groepaz wrote: Fri Sep 11, 2020 7:51 am It would be nice to get some recordings from real HW and the programs that were used to produce them (not only for this sample stuff) so i could put them into the test repo. Small dedicated programs that do nothing but play a certain sound that is, games or demos are not very useful as testcases :)
Which test repo?
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

Noizer wrote: Fri Sep 11, 2020 8:04 am Which test repo?
This one: https://sourceforge.net/p/vice-emu/code ... testprogs/ – heard of it the first time either.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by Noizer »

pixel wrote: Sun Sep 06, 2020 10:22 pm
Am assuming the the playback frequency is just too high because each sample output will take some time to reach it's peak, making the whole thing far too quiet. If there was a regular VIC tone in that piece you recorded, there'd have been blood. ;) Sounds amazing anyhow. How did it come to that fade-out?
We could find out the maximum frequency that makes sense for the loudest output by reading the VICE source code or grabbing an oscilloscope or by asking Mike. :mrgreen: Easing up on the sample rate is the only way to mix "new frontiers in VIC graphics" with "new frontiers in VIC audio". Isn't that what we all wanna experience? :twisted: ...
I think we can certainly improve the code as well as the the volume "hack" which allows to set more resolution than the usual 4 Bit for digis. Maybe "even more bits for the great Denial people"?! 😲
BTW this technique works with my 4 Bit stereo userport DAC and C64 $D418 output too. 😜
Oscilloscope is on the way, until then some pictures showing maybe some approaches for improvement. Enjoy.
AmenBrother-wav
WaveAB.png
AmenBother-spectral view
SpectralAB.png
In comparision, no Audio output after Runstop restore - spectral
NoTone-RunStopRestore.png
In comparision, POKE 36878,15:POKE36877,253 - spectral
Poke36878-253.png
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

Noizer wrote: Sat Sep 12, 2020 3:49 am I think we can certainly improve the code as well as the the volume "hack" which allows to set more resolution than the usual 4 Bit for digis. Maybe "even more bits for the great Denial people"?! 😲
Yep. And I have quite a couple of ideas already. Unless I don't have the real machine back hacking around further on my end isn't too much of a wise thing.
BTW this technique works with my 4 Bit stereo userport DAC and C64 $D418 output too. 😜
Oscilloscope is on the way, until then some pictures showing maybe some approaches for improvement. Enjoy.
AmenBrother-wav
WaveAB.png
Is this all VIC or C64?
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by Noizer »

pixel wrote: Sat Sep 12, 2020 5:48 am Is this all VIC or C64?
100 % Vic20!!! My word
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

OK, it's the VIC. I don't get the meaning of the last two images, though. More sleep required. :mrgreen:
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
pixel
Vic 20 Scientist
Posts: 1357
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by pixel »

I've removed the ear piercing. Would've happened ages ago with a real box but at least VICE got even better. :D
Also I had a flash of insight (including walls rattling) and came up with a full digi volume blast. Problem again: no real machine. There might be an ear piercer again. :( Sounds like the missing resampler thing in VICE though. It's really super-******* loud – the music, I mean.

Now what? Be patient and wait for the first post-pandemic demo party or publish again too early? :twisted:
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: Amen brother ~ 6 bit audio @ 16.3kHz

Post by Noizer »

pixel wrote: Sat Sep 12, 2020 10:48 am I've removed the ear piercing. Would've happened ages ago with a real box but at least VICE got even better. :D
Also I had a flash of insight (including walls rattling) and came up with a full digi volume blast. Problem again: no real machine. There might be an ear piercer again. :( Sounds like the missing resampler thing in VICE though. It's really super-******* loud – the music, I mean.

Now what? Be patient and wait for the first post-pandemic demo party or publish again too early? :twisted:
What’s the problem, dude? Got the Oscilloscope, right here. PM me
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
Post Reply