![]() |
Forum Index : Microcontroller and PC projects : CMM2 loading WAV files into memory to play, possible?
Author | Message | ||||
realmnm![]() Newbie ![]() Joined: 07/07/2020 Location: AustraliaPosts: 34 |
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 KingdomPosts: 10310 |
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: AustraliaPosts: 34 |
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 KingdomPosts: 4311 |
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: AustraliaPosts: 34 |
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 KingdomPosts: 10310 |
See this thread |
||||
realmnm![]() Newbie ![]() Joined: 07/07/2020 Location: AustraliaPosts: 34 |
Thanks, I'll check it out. Martin This signature intentionally left blank. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |