Karoshi MSX Community

Desarrollo MSX => Rutinas - Snipets => Mensaje iniciado por: jltursan en 02 de Octubre de 2006, 07:12:27 pm



Título: 1-bit sample replayer
Publicado por: jltursan en 02 de Octubre de 2006, 07:12:27 pm
Mensaje original de Robsy

Hello everyone! I hope that you will enjoy this one: real sample replayer for MSX, using the keyboard "click" system. It can replay both 11 or 22 KHz WAV files converted from 8-bit to 1-bit.

In order to convert the sample and to view a full example working, download this http://www.robsy.net/sample.zip

Regards!

Código:
;--------------------------------------------------------------------
PLAY_SAMPLE:
;--------------------------------------------------------------------
; Plays a 22,050 or 11,025 Hz 1-bit sample using keyboard click
;--------------------------------------------------------------------
; Parameters: HL=sample data pointer
; BC=sample length in bytes
;--------------------------------------------------------------------
; Modifies: AF,BC,DE,HL,DI
;--------------------------------------------------------------------
; Disable interrupts
di
; Main loop
@@LOOP:
; Set bit counter
ld d,8 ; 8
; Check if finished
dec bc ; 7
ld a,b ; 5
or c ; 5
ret z ; 6 (FALSE)
; Read byte
ld a,[hl] ; 8
inc hl ; 7
@@COPY:
; Extract bit
rlca ; 5
ld e,a ; 5
; Convert to PPI format
ld a,0FFh ; 8
rra ; 5
; Output to PPI
out [0AAh],a ;12
ld a,e ; 5
; Delay - NOPs to sync time
db 0,0,0,0,0,0,0,0,0,0,0,0 ;12*5=60
; Extra delay: uncomment following lines to play 11,025 Hz samples
; db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
; db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
; Check if byte completed
dec d ; 5
jr z,@@LOOP ;13 (TRUE) / 8 (FALSE)
; Balancing delay - additional NOPs
db 0,0,0,0,0,0,0,0 ; 8*5=40
; Continue
jr @@COPY ; 9
;--------------------------------------------------------------------
; Short loop: 162 T-states
; Long loop: 164 T-states
; Perfect 22,050 Hz: 162.5 T-states (for 3.54 MHz Z80)
;--------------------------------------------------------------------


Título: Re: 1-bit sample replayer
Publicado por: jltursan en 02 de Octubre de 2006, 07:14:34 pm
Mensaje original por wyz2

Edu, I'm just trying 4-bit samples too, using a well known methode:

PSG(6)=0
PSG(0)=0
PSG(1)=0
PSG(7)=11111000b

and using PSG( 8 ) as a 4-bit oscilator (By ussing 2 channels, volume and quality are increased a lot)

The way to get a good quality sample from a 8-bit mono 11khz is:


Goldwave:

- Normalize the wave to max. 0.1
- Save the wave as PCM 8 bit-mono unsigned 11khz.

Winhex:

- Delete the &h2C long wav header.
- substract &H78 to all the values (modificar datos)
- search &HF? and change to 0
- search &H1? and change to &H0F
- save the file.( This file could be packed - 70% rate - with bitbuster for example)


...the sample replayer:

Código:
    Code:
    ;[HL]: SAMPLE
    ;[DE]: LENGHT

    PLAY_SAMPLE:
    DI

    PSBC0:
    LD C,8
    LD A,[HL]
    CALL SOUND
    LD C,9
    CALL SOUND
    LD B,6
    DLYBC0:
    DJNZ DLYBC0

    INC HL
    DEC DE
    LD A,D
    OR E
    JP NZ,PSBC0
    RET

    ;SOUND C,A

    SOUND:
    PUSH AF
    LD A,C
    OUT [$A0],A
    POP AF
    OUT [$A1],A
    RET





and It sounds ! :)
http://webs.ono.com/WYZ/4bsample.bin

the original wav was made with text2speech and Goldwave/flange robot2

Note that this methode sounds a little noisy. Try to get a better one, ok?


Título: Re: 1-bit sample replayer
Publicado por: jltursan en 02 de Octubre de 2006, 07:14:59 pm
Mensaje original por Robsy

I have been using the following for the 4-bit PCM:

Channel A frequency=0 (PSG(0)=0; PSG(1)=0)
All channels and noise disabled but square tone in channel A (PSG(7)=&b10111110)

And then I start copying nibbles (4-bit) to channel A amplitude (volume) register, PSG( 8 )=data!

It produces high quality sound if it is well synched. I don't understand why Ricardo Bittencourt talks about the noise frequency register because if it is enabled the sound is much more noisy.
   IP:


Título: Re: 1-bit sample replayer
Publicado por: ARTRAG en 02 de Octubre de 2006, 10:01:50 pm
The PSG volumes are strongly non linear,

go here
http://map.tni.nl/articles/psg_sample.php
to see how this affect the sound you get

and here
http://www.msx.org/PCM-Encoder-0.01.newspost3520.html
to see how the fact that you cannout chage the PSG volumes of 2 or 3 channels
at the same time affect the sound (you get plenty of "clicks") and how
to avoid this with viterbi optimization


Título: Re: 1-bit sample replayer
Publicado por: pitpan en 03 de Octubre de 2006, 10:13:36 pm
The PSG volumes are strongly non linear,

go here
http://map.tni.nl/articles/psg_sample.php
to see how this affect the sound you get

and here
http://www.msx.org/PCM-Encoder-0.01.newspost3520.html
to see how the fact that you cannout chage the PSG volumes of 2 or 3 channels
at the same time affect the sound (you get plenty of "clicks") and how
to avoid this with viterbi optimization

Thank you for your comments, Artag.

Of course that volume levels are not linear: the PSG has logaritmic amplitude levels. I was just testing the whole thing: for game development, 4-bit samples are a waste of space that I cannot afford.

About PSG volume changes, in my 4-bit replayer there is only one channel in use. Pure PCM!

And of course, I learnt a lot at MAP!