-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soundcard Oscilloscope for Pulseview via SDL2 #185
base: master
Are you sure you want to change the base?
Conversation
bb86467
to
a80cda7
Compare
I've fixed some issues. Now the only problem i've noticed is that i cannot stop running acquisition by "stop" button in pulseview and have to wait untill all packets are acquired... Any ideas how to fix this? |
Ok, so i fixed that as well. stop button now works. I think it is ready for review. |
Hi @Harvie kudos!!! Really impressive! What sound card did you suggest? It should be nice to find some low cost USB sound-card compatible. :-) Do you think it is possible to get rid of SDL2? It should be nice if it could work directly with pulseaudio instead of depending an external library. |
@Harvie please rebase your branch repository with master to avoid those issue on your PR. |
I don't think it is a good idea to get rid of SDL2. Libsigrok can be used on other platforms than linux (even on linux not everyone is using pulseaudio). SDL2 makes sure it works on different platforms and in futureproof way, so when somebody invents new audio subsystem for linux we will just build with new sdl2 version without having to port libsigrok to it. for example while i was using sigrok, linux world started transition from pulseaudio to pipewire. so it really makes sense to have another layer. So sdl2 choice was not random, i truly beleive it's a good one. In other words: there's a method to my madnes 🙂 |
I can do that. Will it work? I don't know if hardware driver api is the same for master... |
Something is out of sync, doing a rebase it you fix those issues. Other option is you start from scratch: git pull the master branch of your repo; create a new branch from master; apply your modifications; create a commit and submit a PR. But doing git rebase will save a lot of time. |
Ok, i've rebased the commit. |
Really depends what are you looking for. I use zoom h1n, it is portable recorder which also works as USB soundcard (even on linux), but is not cheap and there are probably better options for that price if you just need soundcard. If you need something really cheap, there are these $1 soundcards. output seems reasonable (depending on chipset, they all look the same, but some are not good), but input is mono: However 24b soundcards with 192kHz sampling are relatively common nowadays for some reasonable price. Not sure if some of them have 5.1 input. That might help as well. It might be cool to use the soundcard with some kind ADUM based USB isolator to enable for galvanicaly isolated measurements. |
I beleive that including this code into sigrok will significantly lower entry barrier to experimenting with analog related features of sigrok and therefore will allow more people to play with it without the hassle of acquiring supported scope and hopefully even draw more attention of contributors to challenges of analog signal processing in sigrok. |
Yes, for sure, although there are those very low cost "saleae" clone (in fact they are not clones) that cost less than U$10. But I think this is a nice feature to have on sigrok. Also it could be used as an analog data logger, correct? |
Yes, these are nice. But they cannot capture analog signals. At least the one i have at hand cannot do that. So there's little to none motivation for contributors to develop any analog related features if they only have these saleae analyzers. But virtualy everyone has soundcard, so now the newbies (like me) can explore early support of analog signals, which is already in pulseview. |
I second the fact that this addition is really helpful, to start playing with Sigrok without any specific hardware, as eg: most Linux systems are sporting a builtin soundcard and SDL2 is available |
Any news on this one? |
Hi Harvie,
Things I'm not so sure about:
|
Recently someone mentioned on mailing list, that github mirror was not updated in a year... https://www.mail-archive.com/sigrok-devel@lists.sourceforge.net/msg04444.html |
Indeed the GitHub master branch is outdated, but it still rebases cleanly on the master branch of the official repo (git://sigrok.org/libsigrok) |
In case you have multiple soundcard, you can select which one to use. At least in pulseview it did worked for me. |
I've fixed these issues and pushed updated version to this PR |
Plugin still leaves some things to be desired. For example support for triggers, which is totaly doable and i would like to add such advanced features. But right now i don't feel like there's much interrest since noone considered merging this in a last year, so such effort would seem rather vain to me... |
Hi @Harvie , first, nice work and actually brilliant idea to come up with a lean driver which supports analog capturing using soundcards - without any HW dependencies on the actual card.
This became actually a huge issue when i was tesing your pull request. I'm not using pulseaudio since it is an audio middleware layer coupled to desktops like Gnome (or in fact it relies on DBUS from what i know) - and i'm more the console user who wants to avoid additional overhead on my Linux boxes. The reason can be found here: Which means: In case of ALSA the device specs are unknown unless you open the device. The result is that ALSA via SDL2 is not working in pulseview or sigrok-cli because SDL_GetAudioDeviceSpec return e.g. 0 channels. I made it working by calling SDL_OpenAudioDevice (with all desired SDL_AudioSpec structure set to 0) and obtained SDL_AudioSpec then holds the default settings. Right after that i called SDL_CloseAudioDevice() again. So just relying on SDL2 is unfortunately not sufficient, we need more testing with different backends - at least the most obvious ones. |
I can try to get this running on macOS 12.1 and Ubuntu Server 22.04. Really cool project. |
another platform to test would be browser via web-assembly, which in principle has access to audio input |
is there web-assembly build of sigrok? there is some sdl2 for webassembly i guess, but not sure sigrok would work anyway... |
No idea, just got the idea while reading about sdl in webassembly for another project |
@christianeisendle That seems as a problem... I am thinking about following fix: I can create wrapper around Do you think this will work? |
Also using ALSA directly is not that common anymore. At least not in mainstream distros and there are reasons for that. I am not saying pipewire is perfect, but it's basicaly what everyone does use now instead of ALSA. |
I think i've managed to fix ALSA compatibility by using following wrapper: int SDL_GetAudioDeviceSpec_open(int index, int iscapture, SDL_AudioSpec *spec)
{
//ALSA does not allow to fully read specs of device without opening it.
//This wrapper tries to open device when SDL_GetAudioDeviceSpec() reports device to have 0 channels.
//See https://github.com/libsdl-org/SDL/blob/237348c772b4ff0e758ace83f471dbf8570535e2/src/audio/alsa/SDL_alsa_audio.c#L759
int ret = SDL_GetAudioDeviceSpec(index, iscapture, spec);
if(!ret && spec->channels == 0) {
sr_err("Failed SDL_GetAudioDeviceSpec(), trying to open device to get specs.");
SDL_AudioDeviceID d;
d = SDL_OpenAudioDevice(SDL_GetAudioDeviceName(index, iscapture), iscapture, spec, spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
if(d) SDL_CloseAudioDevice(d);
}
return ret;
} v3-0001-Preliminary-support-to-use-soundcard-as-oscillosc.patch.txt |
Comments from IRC (mostly by < abraxa_>):
|
6a0cfb6
to
f96542a
Compare
v4-0001-soundcard-as-oscilloscope.patch.txt PATCH v4 has modifications based on IRC discussion with abraxa_
|
PATCH v5: - fixed freeze when using pulse protocol with pipewire - fixed JACK compatibility (forcing integer samples for now) PATCH v4 has modifications based on IRC discussion with abraxa_ Most notably: - Fixed datatype for result of SDL_GetNumAudioDevices() - Using SR_UNIT_UNITLESS instead of SR_UNIT_VOLT - Audio subsystem initialization and scanning is more verbose, giving out useful details for debuging purposes - Better error handling - Code was formated to comply with sigrok rules Signed-off-by: Tomas Mudrunka <mudrunka@spoje.net>
v5-0001-Support-use-of-soundcard-as-oscilloscope-via-SDL2.patch.txt PATCH v5:
|
This looks incredibly useful. Really hoping to see this merged into mainline sigrok. Great work, @Harvie!! |
Hello,
inspired by xoscope http://xoscope.sourceforge.net/
i've created libsigrok driver which enables oscilloscope-like acquisition via arbitrary soundcard.
My goal is to be able to decode 9600 baud UART signal captured by soundcard in pulseview.
I've tested it only on linux, but it uses SDL2 library and therefore should be quite portable (most likely without any modifications, can someone please try to build on windows? there is even sdl2 on android, but i am not sure how that works).
I think the concept is relatively usefull. Definitely for education, but i beleive it can be even useful for serious work, since high-end soundcards now have lots of channels and samplerates in hundreds of kHz. Also on raspberry pi and similar devices you can use rather interresting I2S ADCs with specs far behind your traditional audio needs (even with DC coupling possibilities). Some people even managed to modify cheap usb soundcards to remove DC blocking capacitors enabling them to do DC measurements.
i think in future it might be possible to add continuous acquisition, downsampling for long-term measurements and even triggers (should be quite easy) and more. Anyway here is screenshot of noise captured by my laptop's microphone:
It can already detect multiple soundcards and lets you chose from them, autodetect number of channels, audio format and sampling rate. (though i might still need to properly scale the signal to some reasonable voltage values)
**
PS.: not sure why i see @uwehermann commits in this PR, my code is in single commit.
(i've based my work on libsigrok 0.5.2, since that is what i use on archlinux and i didn't wanted to use git build of pulseview, perhaps there were some extra commits under that tag)