Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:37 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2 loading WAV files into memory to play, possible?

Author Message
realmnm

Newbie

Joined: 07/07/2020
Location: Australia
Posts: 34
Posted: 02:47pm 29 Jul 2020
Copy link to clipboard 
Print this post

I'm trying to add sound to my program, the problem is they are small WAV files, so loading them constantly to play is killing performance.  Would it be possible to load them into buffers at the start, and then play back from the buffers as needed?

Martin
This signature intentionally left blank.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 03:27pm 29 Jul 2020
Copy link to clipboard 
Print this post

If they are small you can load them into arrays and then use the DAC command to play them. Also reducing sampling rate and using mono files reduces overhead
Edited 2020-07-30 02:05 by matherp
 
realmnm

Newbie

Joined: 07/07/2020
Location: Australia
Posts: 34
Posted: 09:04am 30 Jul 2020
Copy link to clipboard 
Print this post

The small ones I am most interested in are around 7000 bytes, so to enter into an array either manually or via an external method is not really feasible.

I tried:

1 - opening the files to read, but hit the EOF not far in
2 - read the file using input$(nbr, #) but that complains about > 255 chars
3 - as per #2, but 255 bytes and then longstring concat, but then input$ uses a string and you can't concat the two types.

I thought about reading them into a different page and then copying that to an array, but then I would have to translate the file into an image format or sprite format to be able to read it.

So I don't think it is really possible at the moment to do this.

Martin
This signature intentionally left blank.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 09:12am 30 Jul 2020
Copy link to clipboard 
Print this post

Use LongString Append.

See the mem_init() function here https://github.com/thwill1000/zmim/blob/master/src/mem_cmm2_fast.inc for how I am filling the m() array by reading a file.

Regards,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
realmnm

Newbie

Joined: 07/07/2020
Location: Australia
Posts: 34
Posted: 11:54am 30 Jul 2020
Copy link to clipboard 
Print this post

  thwill said  Use LongString Append.


Thanks, I can now read the file by using append, however when I play it back there is some noise on playback.  I tried swapping bytes, words, and combinations of the two thinking it might be an endian thing, all it did was made it sound worse.


Here is test program that plays the WAV file, I'm ignoring the headers and just playing those, but that shouldn't add noise to the rest of the playback that you can hear.

soundtest.zip

Martin
This signature intentionally left blank.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 12:06pm 30 Jul 2020
Copy link to clipboard 
Print this post

See this thread
 
realmnm

Newbie

Joined: 07/07/2020
Location: Australia
Posts: 34
Posted: 12:13pm 30 Jul 2020
Copy link to clipboard 
Print this post

Thanks, I'll check it out.

Martin
This signature intentionally left blank.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025