Sound DMA, MEMC, what's up there ?

discuss general risc os software applications and utilities
Related forum: adventures


Post Reply
User avatar
ericde45
Posts: 71
Joined: Sat Feb 13, 2021 12:49 pm
Contact:

Sound DMA, MEMC, what's up there ?

Post by ericde45 »

Hello,

i switch from working on video to sound
( my attempt to change video pointers works fine :) )

when allocating video memory, i run a SWI OS_ChangeDynamicArea
then i can write in the video memory , and change vstart and vend directly in the hardware registers.

i tried to change the sound dma, Sstart and SendN
i setup and start the sound using SWIs, i can change the frequency in the 0xC0 register and i can here the difference, but i am not able to set the DMA start and length. the sound played seems to be a read of a part of the memory but no the one where i put my mu-law sample.

do i need to do something like allocating memory to Sound like i did for video ?

does the MEMC control my access to memory and avoid me from putting the start of the sound dma where ever i want ?

my code is running with Risc OS stopped, only vsync running and unmasked, and i set my own VBL code in 0x18

( thanks to Rasterman, i made a lot of progress )

once again i think i missed something.
steve3000
Posts: 2464
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by steve3000 »

Great that you're making progress!

Yes - sound is like video - same chips (MEMC to allocate memory, VIDC plays the sound) same restrictions.

So you need to place your sample in the first 512kb of physical mapped memory (same as video). Also you need to choose 1, 2, 4 or 8 channels and interleave your sample bytes according to the number of channels.

Hope that helps.
User avatar
ericde45
Posts: 71
Joined: Sat Feb 13, 2021 12:49 pm
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by ericde45 »

thanks for your answer

for what i understood regarding the number of channels, and this is not completly clear in the VLSI documentation, if i put the same stereo value for all the channels ( registers 0x60-0x7C) , i end using one channel. At the frequency entered in register 0xC0 :
"When only one channel is used, all eight registers should be programmed with the same value."

but regarding memc and dma registers : for video, i was able to allocate memory and it was allocated starting from address 0, so i used that to write to dma. ( and added the size of 1 screen to find the real physical address of the second screen.)

but how do i convert a given memory address to find the real physical address that i can put in dma registers ?
and using OS_ChangeDynamicArea, which kind of memory shall i ask. shall i choose something like RMA or system heap ?
or put my sound in the video memory, after the real part that is displayed ?

edit : i searched a lot through SWI calls, but the interesting ones are not available in Risc OS 3.11 : swi &68, swi &66
User avatar
SKS1
Posts: 25
Joined: Sat Sep 19, 2020 12:04 am
Location: Highland Perthshire
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by SKS1 »

I'd advise running sound via the Sound system, which takes care of allocating DMA-able memory. Use SWI Sound_Configure to get it to call your routine to fill the DMA buffer. Obvs you'll have to have sound interrupts enabled! Just use RISC OS 3.1 era documentation: e.g. http://www.riscos.com/support/developers/prm/
Last edited by SKS1 on Fri Jun 04, 2021 10:21 am, edited 3 times in total.
User avatar
ericde45
Posts: 71
Joined: Sat Feb 13, 2021 12:49 pm
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by ericde45 »

that's really not my aim
even QTM is handling too many cases, using cpu time for this

i am aiming at converting the LSP from Arnaud Carré, that generates 68000 code directly instead of reading a module, so i won't use the risc os slow and complex sound system.

i only want to be able to write dma buffers and change the frequency ( the swi calls for that seems to bug )
User avatar
SKS1
Posts: 25
Joined: Sat Sep 19, 2020 12:04 am
Location: Highland Perthshire
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by SKS1 »

You could, however, just respond to the first couple of fill requests with 0dB data, noting the addresses it asked you to fill (there will be just two of them) and then taking over the sound system and filling yourself as needed.

[Edit. "how do i convert a given memory address to find the real physical address that i can put in dma registers" - you don't. If you want DMA-able memory, just allocate more memory into the ScreenArea.]
User avatar
ericde45
Posts: 71
Joined: Sat Feb 13, 2021 12:49 pm
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by ericde45 »

in fact it is possible, as it is done in RasterMan :)
i checked it back and found the lines calculating page+offset of a memory address

so i am progressing !
User avatar
SKS1
Posts: 25
Joined: Sat Sep 19, 2020 12:04 am
Location: Highland Perthshire
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by SKS1 »

I presume RasterMan is examining the soft copy of the CAM to achieve this?
steve3000
Posts: 2464
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by steve3000 »

SKS1 wrote:
Fri Jun 04, 2021 1:14 pm
I presume RasterMan is examining the soft copy of the CAM to achieve this?
Correct, using SWI OS_ReadMemMapEntries.
steve3000
Posts: 2464
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by steve3000 »

ericde45 wrote:
Fri Jun 04, 2021 12:56 pm
in fact it is possible, as it is done in RasterMan :)
i checked it back and found the lines calculating page+offset of a memory address

so i am progressing !
=D> :D
steve3000
Posts: 2464
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by steve3000 »

ericde45 wrote:
Fri Jun 04, 2021 9:51 am
i only want to be able to write dma buffers and change the frequency ( the swi calls for that seems to bug )
There are several bugs in SWI Sound_Configure, but these bugs are different in RISC OS 3.1, 2.0 and Arthur. As I recall most issues relate to restrictions on setting frequency with different numbers of channels enabled and/or correction factors applied by RISC OS when running the VIDC at a clock speed other than 24MHz. QTM navigates around these bugs, but if you are careful when setting up channels yourself with the VIDC, and stick to 15KHz screen modes from the 24MHz VIDC clock, then you should be ok.
User avatar
ericde45
Posts: 71
Joined: Sat Feb 13, 2021 12:49 pm
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by ericde45 »

Steve,
i was not able to find how you allow your dma buffers in QTM for A2 Risc os 3 computers ?
logical addresses i found are &1F06000 and &1F07000, but i can not use them without a proper allocation :(

i tried to find the physical addresses for this 2 buffers, and they are above 512 Ko as expected.

but i can not write directly to these adresses.
steve3000
Posts: 2464
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by steve3000 »

ericde45 wrote:
Fri Jun 04, 2021 8:45 pm
i tried to find the physical addresses for this 2 buffers, and they are above 512 Ko as expected.
They should not be above 512k in physical space, they must be below, because only 0-512k is accessible by VIDC DMA.

I've attached here a simple piece of BASIC code I wrote in 2013 to find the physical address from logical address using OS_FindMemMapEntries. When using RISC OS to return the physical address, first make sure you first set up sound in RISC OS (select 1, 2, 4, 8 channels, correct frequency, DMA size) as you require for your code.
Attachments
GetPhysical.zip
Logical to physical address translator
(1020 Bytes) Downloaded 4 times
User avatar
ericde45
Posts: 71
Joined: Sat Feb 13, 2021 12:49 pm
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by ericde45 »

i made a mistake with my english, i meant below of course

i already found the code to translate logical to physical in Rasterman
but my question is how do you find or allocate the logical addresses i listed : &1F06000 and &1F07000
steve3000
Posts: 2464
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by steve3000 »

ericde45 wrote:
Sat Jun 05, 2021 5:53 am
i made a mistake with my english, i meant below of course

i already found the code to translate logical to physical in Rasterman
but my question is how do you find or allocate the logical addresses i listed : &1F06000 and &1F07000
Ah, no problem.

If you want to read the addresses that RISC OS sets up for sound DMA, this is not simple because I don't think RISC OS provides a call for this...QTM finds these addresses because it registers itself with RISC OS as a sound DMA handler, and records the buffer addresses when called.

However an easy method would be for you to set up a simple imitation sound DMA handler routine and register it with RISC OS using Sound_Configure. A simple piece of code which stores the buffer location (provided in R12) then exits, should be fine. The location of one DMA buffer is passed to the handler when RISC OS calls it the first time, and the second buffer is passed on the second call. Store both of these, then remove your handler using Sound_Configure... Your imitation sound handler only needs to be active for two buffer fills, so wait a couple of Vsyncs should be enough.
sirbod
Posts: 1221
Joined: Mon Apr 09, 2012 9:44 am
Location: Essex
Contact:

Re: Sound DMA, MEMC, what's up there ?

Post by sirbod »

steve3000 wrote:
Sat Jun 05, 2021 9:33 am
However an easy method would be
In this instance he could just hardcode the addresses as this is only ever going to work on a small subset of machines, all of which use the same logical address for the sound DMA buffers.
Post Reply

Return to “32-bit acorn software: other”