How to do USB audio
Pages: 1 ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ... 52
Ronald May (387) 407 posts |
Yes, but the point is, the usb device is locked to only send that much data in real time, so it is just another useage of /that/ device. The same thing is going to happen if you want to play an MP3 flac optus or whatever compressed file you choose to play, they will be supersized as they go into the 48000Hz 16 bit wave device, normally without creating temp files though. You can farm out this work to a remote playing device to avoid expanding the compressed audio on your local machine in many ways if you prefer to do it that way. Up until now the average audio output of RISC OS machines could be matched or bettered by using a portable device, the desktop gives a more direct interface to your media libraries, and there will still be a need to send media files to a TV or related player, rather than playing video’s in RISC OS. Audio, OTOH can be handled reasonably well, especially with Dave and Colins improving of the available options. |
Ronald May (387) 407 posts |
I have had a play with the cheap ‘3D SOUND’ dongle with mic and out sockets. Rather than use “end by pressing any key” which for some reason led me to using ESC, I reduced the number of keyboard scans and stopping the recording session now requires a firm press on the End key, with this change.
ctr% is initialised to 0 at start of program. Edit: Processing the mic input in a quick way for compressing or reducing the size will be another thing, I have noticed programs with functionality for telephony and opus has a voip mode. The new opus 1.1 claims 30% less cpu useage for arm, but they will be using the extensions I imagine. Opus seems to be crawling on my Iyonix. |
jim lesurf (2082) 1438 posts |
I may be wrong as my memory is unreliable. But I think sox uses ssrc. Whatever, it gives good quality results using its defaults.
Alternatively, simply summing/averaging the two may be quick enough. Watch out for unintended overflows, though! I think I caught at least one version of Audacity showing the signs of this. That said, in general I’d advise keeping recorded values well below max as otherwise even the simplest process can produce overflows or clipping. Jim |
Colin (478) 2433 posts |
My cheap sound dongle is a C-Media device and only records 44100 and 48000 mono. There seems to be a lot of devices with C-media firmware I’d be interested if you’d run USBDescriptors.zip with the device plugged in to see what its capabilities are. |
Ronald May (387) 407 posts |
Colin, Jim, yes I have read good things about the sox resampler, I built the smaller libsoxr but it doesn’t come with a ready made resampler binary. |
jim lesurf (2082) 1438 posts |
Having now sent off something I had a deadline to write I hope to switch my attention (such as it is!) to experimenting some more with USB. One part of that will be to get some new devices to try. I’ll report on that when I have more ideas. The other is to write some simple ‘C’ progs to get familiar with how to use the modules. Colin: I know that Dave has published an API document, but I can’t recall if you have. Is this now set well enough and available? Otherwise I’ll have to try an work things out by head-scratching over the BASIC in your player! Jim |
jim lesurf (2082) 1438 posts |
Fairly “off the wall” question/idea… Would the ResourceFS approach (as per Colin’s demo) work using !GraphTask running a program in ‘C’? Since I’ve almost never done any wimp programs that might make it easier for me to do a more ‘interactive’ demo player. I’ve just done some quick tests using !GraphTask from http://www.armclub.org.uk/free/ and the supplied (BASIC) progs run happily on my ARMiniX. However the help file does say “Works if you: Do not claim operating system vectors or use interrupt code."Does that rule it out? I’m thinking of a player that will graphically show the file details, elapsed time, and give a slider bar to change the point being played, etc. FWIW Under Linux I’ve used SDL for doing a GUI for playing (and grabbing) audio. But of course there you don’t need to deal directly with the desktop multitasking. Jim |
Colin (478) 2433 posts |
Jim. ResourceFS? Yes you can write the program using !graphtask but it will have the same problem of any application space program ie it will pause when f12 is pressed. I’d be inclined not to use stdio. The USB part is simple. Just open a file, write bytes to it and close it. When using my IsocPlayer a line comes up something like
that’s the filename. |
Colin (478) 2433 posts |
Ronald. I don’t know how you got 24000 and 22050 stereo the device claims only to be 48000 or 44100 mono. |
jim lesurf (2082) 1438 posts |
For my idiot-simple test/demo purposes I’m not worried about it being vulnerable to f12, etc. Just want something that gives more userinfo and control to illustrate and look a bit neater. No-one in their right mind would use what I’d write as their standard player, I hope! I hope someone cleverer than me writes a sensible desktop app or alters a familiar player to output to USB! Maybe the ugly nature of what I’d do would spur a better programmer offended by the awfulness of what I did. 8-] But it will help me suss out things without having to learn how to write wimp apps whilst I’m trying to make sense of the USB audio as well. I just had a go, and yes, I altered a line in your main player program to specify the input file for simplicity. Then dropping the resulting prog onto graphtask caused it to run the program and play the file OK. Output appearing in the graphtask window. So I’ll use this to play… erm learn with. I presume from what you say that I write the bytes having added/removed bytes when needed to match the DAC requirements? e.g. if the DAC wants 4bytes/sample and I’m playing a 16bit file I give the dac 2 data-from-file bytes followed by two zero-bytes per sample? Once I get the hang of this I can also use it to play… experiment with inbuilding conversions, etc. eg experiment with adding upsampling or scaling using 24bits, etc. Also, when I get an ADC it may let me write an equivalent to my old !IyoScope for ARMiniX, etc. Found that useful as a scope/FFT/signal analyser at times. It will also help me when I finally get back to writing the ROSS document and I add a section on the ‘proposed’ API, etc, details for inclusion of USB audio. Jim |
Ronald May (387) 407 posts |
‘I don’t know how you got 24000 and 22050 stereo’ |
Colin (478) 2433 posts |
If you look at the descriptors your device only has 1 interface to record data (only 1 Audio Streaming interface with an IN endpoint). The interface is described in a collection of descriptors one after the other. So the recording interface on your device is:
This is where xInterface% and xAlternate% comes from xInterface% = bInterfaceNumber and xAlternate% = bAlternateSetting.
This tells you that the interface transfers PCM data.
This is the descriptor which tells you the format of the data. This is where xChannel%, xSamplerate%, xSamplesize% and xBits% comes from. xChannel% = bNrChannels, xSamplerate% is either 48000 or 44100, xSamplesize% = bNrChannel*bSubFrameSize and xBits% = bBitResolution. Note the bit resolution does not affect the sample size. bBitResolution is really the significant bits in a bSubFrameSize sample. xBits% and xChannel% are not used to open the USB endpoint they are used to create the wav file header.
This is where the xEndpoint% value comes from xEndpoint% = bEndPointAddress.
And finally the interface has this descriptor which describes the delay in locking on to the frequency. If the device had a stereo recording interface as well as a mono recording interface it would need another set of interface descriptors describing a stereo interface ie it would have bNrChannels = 2 and different interface,alternate and endpoint numbers. I think your stereo is 2 channels playing alternate mono samples ie you’ve just changed the wav file header. There is no way to tell the device to send stereo |
jim lesurf (2082) 1438 posts |
I’ve been looking again at your code, Colin. Alas, I’m still getting stuck by trying to work out what SYS/SWI calls, how, set up the transfers. I’m still not clear on various points and suspect I’m muddling different things together. Also having trouble seeing what’s happening because I’ve not used BASIC for so long that I keep having to work out or check simple lines! :-/ My initial assumption is that to have the program work I need to: A) Locate what (if any!) USB audio devices are available and determine what sample rates, etc, they can accept, and details like how many bytes per value they require. B) Tell the device what rate, etc, I want for a transfer. C) Initiate a save and then save the data payload into the ‘file’. D) Clear the transfer so the device knows this has finished. But I suspect I’ve misunderstood. Is it that I should simply regard playing as the process of saving a file of the data payload and all the specs are in the filename? That does ring a bell with what I did using !AudioIn to use the Iyonix as a scope. So, you gave the example USB8#nopad;noblock;size176400;samplerate44100;samplesize4;interface1;alternate1;endpoint1: I want to check the syntax here. Is there no preceeding file system before the “USB8”? And I guess I should also ask how I determine that USB device ‘8’ is the one to use. However I can always do a *usbdevices first and find out for now. :-) size seems to be samplerate * samplesize, whose values seem clear enough. But how do I determine the interface, alternate, and endpoint values? For initial tests I can note them from running your own program. But at present I can’t see though the BASIC to see how you find the values for such things. Sorry I’m a numpty wrt BASIC, etc. Jim |
Dave Higton (1515) 3526 posts |
Jim: the whole point of writing the USBAudio module was to abstract application writers from USB, and thus not have to understand much (if anything) about USB. So why not use the USBAudio module, which, after all, does have a published interface? And example code, too, in the form of my UAPlayer application. |
Ronald May (387) 407 posts |
‘I think your stereo is 2 channels playing alternate mono samples ie you’ve just changed the wav file header. There is no way to tell the device to send stereo’ Yes you are right, I did suspect it might be just reordering, which is why I refrained from saying stereo, and described it as 2ch. I have now checked with a proper left-right test signal and can say that it is recording both left and right as one and then pouring the mono stream into the 2 channels. |
jim lesurf (2082) 1438 posts |
I was/am planning to also do that. However at present I’m trying to avoid also writing a WIMP application as that adds complications for me. Also, one of the main points is to let me learn and illustrate when I write documentation others can follow. I tend to take the view that the best way to understand something is to learn enough to be able to make it work and satisfy myself I’ve understood the necessary details sufficiently. So if I find writing something using what seems like the simple ‘direct’ “write to a file” ResourceFS method, then I’ll switch to something based on your module as my first effort. I’d still want to come back to the ‘file’ method, though in time. Would your module also work from GraphTask? Or would that be problematic? Actually, presumably I could use your module to get device details even if the program then used the ResourceFS / file approach for playout? And is it a bad thing if I nudge Colin into specifying his API / SWI uses explictly? Will make it easer for me to explain to others. :-) Jim |
Martin Avison (27) 1494 posts |
Jim, |
Dave Higton (1515) 3526 posts |
No connection with either of the above. It will “just work”. You do seem to see complications where none exist… |
jim lesurf (2082) 1438 posts |
Not doing that. I’m writing in (Norcroft/Acorn/ROOL) ‘C’ (or at least intending to). One of my problems is that it is many years since I wrote anything in basic. But I’m hoping to have the program work using !GraphTask which is a way of allowing a taskwindow to show graphical results. i.e. I can draw things like colour progress bars/thermometers, etc, to give an apparent GUI more like a typical wimp amp. Jim |
jim lesurf (2082) 1438 posts |
bq.bq. Would your module also work from GraphTask?
When lucky, yes. :-) I’ll have a play using your module with GraphTask. But no doubt I’ll end up head-scratching over BASIC again. 8-/ Jim |
Colin (478) 2433 posts |
Forget about BASIC your first problem it seems to me is you don’t know how to read and write to a file using RISC OS.
Forget about that you want open and close to be based on Daves module. |
Colin (478) 2433 posts |
Oh and what has ResourceFS got to do with anything? |
jim lesurf (2082) 1438 posts |
OK. I’ll have a go tomorrow. (Had to go out this afternoon.)
Probably a sign of my lack of understanding. But I’d though that the way your modules allow the use of ‘file’ transfers was an instance of a ResourceFS-like filing system. Jim |
Rick Murray (539) 13840 posts |
I can’t help but wonder if you aren’t going to be making things more difficult for yourself by doing it this way? It isn’t so hard to make a little desktop application to oversee music playback, this is one I wrote a billion years ago for playing CDs – http://www.heyrick.co.uk/voyager/mewzyck.html – I might even have the source still kicking around someplace. ;-) One thing I would suggest is that you try – if possible – to separate the fancy UI and the physical playback. This is because you cannot tell what the latency of the Wimp polling will be. As the system uses co-operative multitasking, applications cede control when they are ready. While you can work out how long each loop around is using heuristics, what happened in the past is no reflection on what will happen the next time around. You’ll notice that multitasking players (pick one!) tend to have the back-end as a module which will get on with the boring grunt work pushing data around (on callback or buffer empty event) and the front end will do all the interfacing with the user. [this also means it should survive an F12, but things might get unstuck if the user is out of the desktop when the current song finishes!] |
Raik (463) 2061 posts |
Sorry, I’m new on this thread ;-) Last year I have buy a box called “Xpress Dock” for my Pandora-Dock and works fine with Linux The box is a USBHub 4x … works also with RISC OS With 3. I play around a little bit on my Panda and with the Software from this thread. I try also !UAPlayer after I load USBAudio. If I drag a ISOSample on it I became a Error: No matching parameter set at line 1580 What can I do, what is my mistake? Is it possible tu try audio in? Many thanks. |
Pages: 1 ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ... 52