Jump to content
IGNORED

Looking routine to play sample sounds


Recommended Posts

Hi Guys,

 

i am looking for a simple routine that can play wav (sample voice) sounds on the atari 8bit (with antic on)

any one can direct me to information or the link to a previous thread discussing this issue.

 

thanks

ndary

 

 

Link to comment
Share on other sites

Playing samples (page aligned) is basically:

 

	mwa #sample zp
	ldy #0

loop
	lda (zp),y
	ora #$10	; optional, if you preset the volume-only bit
	sta WSYNC	; repeat for lower sample rates
	sta AUDC1

	inc zp
	bne loop
	inc zp+1

	lda zp+1
	cmp #>samplend
	bne loop

This is with unpacked 4-bit samples. With packed 4-bit, it's something like:

	mwa #sample zp
	ldy #0

loop
	lda (zp),y
	tax
:4	lsr
	ora #$10
	sta WSYNC	; repeat for lower sample rates
	sta AUDC1

	txa
	and #$0f
	ora #$10
	sta WSYNC	; repeat etc...
	sta AUDC1

	inc zp
	bne loop
	inc zp+1

	lda zp+1
	cmp #>samplend
	bne loop

Untested live coding in the AA editor, but you get the drift :)

 

If you want to keep the screen on, you have to disable VBIs and DLIs.

 

You can also run the replay routine from a timer IRQ at 15.6kHz, or 7.8kHz, etc...

Edited by ivop
Link to comment
Share on other sites

Pokey Timer is the best method especially if the screen is displaying something.

 

Wait on WSync or VCOUNT is OK also but means the CPU is at 100% and also ties you to that particular sample period (or multiple of)

Simple delay loop is a primitive method and not well suited if a display is present as you get way too much variation in the real time elapsed.

Edited by Rybags
Link to comment
Share on other sites

Hi Ivop, 

 

how you convert the WAV file to raw sample data? what too you use?

 

13 hours ago, ivop said:

Playing samples (page aligned) is basically:

 


	mwa #sample zp
	ldy #0

loop
	lda (zp),y
	ora #$10	; optional, if you preset the volume-only bit
	sta WSYNC	; repeat for lower sample rates
	sta AUDC1

	inc zp
	bne loop
	inc zp+1

	lda zp+1
	cmp #>samplend
	bne loop

This is with unpacked 4-bit samples. With packed 4-bit, it's something like:


	mwa #sample zp
	ldy #0

loop
	lda (zp),y
	tax
:4	lsr
	ora #$10
	sta WSYNC	; repeat for lower sample rates
	sta AUDC1

	txa
	and #$0f
	ora #$10
	sta WSYNC	; repeat etc...
	sta AUDC1

	inc zp
	bne loop
	inc zp+1

	lda zp+1
	cmp #>samplend
	bne loop

Untested live coding in the AA editor, but you get the drift :)

 

If you want to keep the screen on, you have to disable VBIs and DLIs.

 

You can also run the replay routine from a timer IRQ at 15.6kHz, or 7.8kHz, etc...

 

Link to comment
Share on other sites

Usually a given PC based utility will only work down to 8-bit samples.

 

I've always just used a quick self-written program to convert.  Use input of either 16 or 8 bit (preferably unsigned) sample data.

Either throw away the lower bits (integer divide) or use rounding to get 4 bit samples.

Then pack those samples, high/low into 8 bits and output to a file which then is read into the Atari.

  • Like 2
Link to comment
Share on other sites

9 hours ago, ndary said:

how you convert the WAV file to raw sample data? what too you use?

I used to use sox to convert to 8-bit 7800Hz unsigned, or 8-bit 15600Hz unsigned, and save as RAW. Then I used to have (can't find it) a small tool that divides all bytes by 16 (shift right four times). Be sure to use a SINC resampling to avoid aliasing, and normalize so your 8-bit sample with only 7-bits dynamic range won't turn into a 3-bit sample. You can also export to WAV so you can replay it at your PC to listen to the quality. Reexport as RAW when your done, or cut-off the first 44 bytes of your final WAV file.

  • Like 1
Link to comment
Share on other sites

Hi Ivop,

 

"You can also export to WAV so you can replay it at your PC to listen to the quality. Reexport as RAW when your done, or cut-off the first 44 bytes of your final WAV file."

 

 This is something i can do with AUDACITY

 

ndary

Edited by ndary
Link to comment
Share on other sites

I usually convert the 16Bit stereo WAV into 8Bit mono WAV with Wavosaur or Audacity, then transfer the WAV to the Atari and there convert the 8bit mono WAV into a 4Bit mono sample... just for fun.

 

(And some days ago I also converted approx. 20 MP3 songs into 8Bit mono WAV and kept only the first 5-10 seconds of them, then transfered them to the A8 and saved them on ATR images together with The Sound Utility by CTH/Tom Hunt which is a WAV player for 8bit mono WAVs on the A8; it supports XRAM up to 1MB.)

 

There are many other ways to convert a WAV into an A8 sample, e.g. I have some old PC files that work under WIN XP command prompt and a) convert WAV into sample (and sample into WAV), named WAV2SMP.EXE as well as b) convert 16Bit mono WAV into 4Bit mono sample, named Convert4.EXE.

 

wav_conv.zip

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

17 hours ago, ndary said:

 This is something i can do with AUDACITY

Yes. Load WAV file, convert to mono, resample to 15600 (Tracks->Resample), export as 8-bit WAV. Not sure if the resampler is a proper resampler, so best do a low pass filter on half the replay rate (7800Hz in this case) on the original WAV file and then reample to 15600.

 

Link to comment
Share on other sites

somewhere in the forum I might have posted the IRQ sample player I got from Space Harrier XE coder and I used that in Gridrunner. Miker did all the sample conversion on PC for it.

 

something like every 2nd scanline IRQ was fired to play a byte of sample. not sure if it was 4bit nibble packed. tooo long ago or me getting old :D

 

  • Like 1
Link to comment
Share on other sites

Here's an example that I made for ndary in PM:

 

sample.zip

 

The Makefile shows the sox commands that you can use to convert to 8-bit raw files with sample rates of either 4k or 8k. It also shows a Perl one-liner to convert 8-bit raw files to 4-bit raw files.

 

Run test.xex and press 1-5 to hear various techniques and sounds:

  1. 4bit 4k sample rate "barrel roll"
  2. 8bit 4k sample rate "barrel roll"  2X RAM consumption
  3. 4bit 8k sample rate "barrel roll"  2X RAM consumption 
  4. 4bit 4k sample rate "bubblegum"
  5. 8bit 4k sample rate "bubblegum" 2X RAM consumption
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...