Find the answer to your Linux question:
Results 1 to 7 of 7
Hello, i need a small console application (with source), and i will pay 75$ for that via paypal - or make a suggestion - please simply contact me via private ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2012
    Posts
    4

    Post Console based audio player - controllable via stdinput


    Hello,
    i need a small console application (with source), and i will pay 75$ for that via paypal - or make a suggestion - please simply contact me via private message.

    A) It needs to be a (simple) native console application (written in c/c++), thats permamently reads the stdinput. When it read this line:
    "play:<path to song.wav>\n", it should play the given wav file.
    B) "stop\n" should stop the song.
    C) Caching the wav-file in memory. I never play more than 5 songs, so dont worry about memory usage.
    D) I't not wished, that the console application runs another process like aplay or paplay.
    E) When new song should played, while another song is beeing playing, it should be stopped (no fading out requied).
    F) You can use pulseaudio or alsa. When using alsa, you need to keep the device open! This means: On start of the application, grap directly the audio device,and never close it. Otherweise i will hear a bad noice at the begin and end of every song. In pulseaudio, it not requied, because i can disable the "idle-mode".

    Why i need this:

    I have a C# application (chess application) on a ARM board. When using aplay, i hear a noise at the start and end of every song (when grapping/ungrapping the audio device). This is a problem of hardware. When using pulse audio with disabled idle-mode, the audio device will be active all the time, no noise is there, when a song begins/ends.

    The next problem is, when using paplay(or even aplay), it's too slow! I'm not very sure "why" it's too slow, but between the "play-trigger" and the read sound, there are 1-3 seconds. The ARM computer is slow, runs at 700Mhz and has a SDcard as storage (Rasphery PI, running Raspian, depian wheezy ARM-version).

    So the console application needs to run all the time (my c# application will run it), and listen on the stdinput for "play:<song>\n" and "stop\n" commands. When becoming a "play"-command, it should play the song "instantly" (for the first time, when the wav-file is not cached, its ok, when its not "instantly"). So, calling a child application like aplay/paplay is not wished - my application would be able to do this at theiry own

    The song needs to be there "instantly", because it's a physical interaction, and it's not wished, that the sound will be there 1 s later started. It should be as fast as possible. The duration of the sound is round about 0.5-3 seconds (moving a pice on the board, "your turn", "thinking", "check", "check mate).

    Please keep in mind: The ARM computer is slow.....every slow.

    And why i don't do it directly in c#? Lack of libraries with .NET bindings, that offer a audio interface Even with gstreamer, i have lots of problems. I tried to adapt some source snippets from Bansee.fm, but it's GUI-app, and on the other hand, they are using jackd (it seems), and for jackd, the memory is too less.

    Another idea was to use other console based players, but they are opening/closing the device before/after every song - so i hear the noice. And i cannot send CTRL-keys via stdinput.

    Feel free to aks questions.

    Greetings,
    Sebastian

  2. #2
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    344
    .NET bindings? Are you talking MS .NET Framework? If so, I'd hazard to guess that is the reason why everything is slow. Every box I've had that on just crawls, until I get rid of it.

  3. #3
    Just Joined!
    Join Date
    Dec 2012
    Posts
    4
    Not Microsoft .NET, it's mono(unix implementation). But that's not the point. Even when typing aplay/paplay test.wav in native terminal, it's slow. This ARM computer is no performance monster

    Hm, i found out, when using pulseaudio with disabled idle (suspend on idle), no sound will there. I will get the mesage "Failed to drain stream: Timeout" when using paplay.

    Greetings,
    Sebastian

  4. #4
    Just Joined! r1cs's Avatar
    Join Date
    Mar 2007
    Location
    Russia
    Posts
    9
    For speed up loading files you can copy them into memory using tmpfs. It'll be simpler and better solution than caching.
    If you'd like I can develop the player. Even without payment, "just for fun".

  5. #5
    Just Joined!
    Join Date
    Dec 2012
    Posts
    4
    Hello r1cs,
    tmpfs will not solve it, the problem is the startup/initialization/loading of the app, too. The problem are the only 700Mhz of the ARM-Computer.

    Thank you for you offer to implement the console player. But for now, i hope i've solved my issues. I was able to control the ALSA-Device directly via C#. It seems to work now. I have still to fight with some issues, for example, somtimes it hangs on the "snd_pcm_writei" method (in libasouond.so.2). But normally, this function should never hang. I'm not sure, if this is a hardware bug of the sound chip (BCM2835), or a driver bug or problems in the linux kernel (ARM CPU architecture version of debian, soft float compiled). I was even able to produce kernel panics, when i play specific WAV-combinations - even with only user rights.

    For example, i have WAV-file A, B and C. I can play file all files without problems. But when i play file A and than B, it will hang. but i can play B and C how often i want. They have all the same bit rate, codec, mono-channel and so on (checked with audio editing software). Its really funny to see (no, its annoying) that this file works, but another not.

    As it seems, it works "all", when i "close" the sound card and reopen the device. But than i hear the "pops" in the speaker - yeah, cheap hardware. Another solutdion could be to plug a USB-soundcard on it. But because this is all for a wooden chessboard, i need to keep the hardware price (production costs) low.

    Greetings,
    Sebastian

  6. #6
    Just Joined! r1cs's Avatar
    Join Date
    Mar 2007
    Location
    Russia
    Posts
    9
    Quote Originally Posted by Arakis View Post
    somtimes it hangs on the "snd_pcm_writei" method (in libasouond.so.2)
    Then maybe you should set non-blocking mode and use function snd_pcm_poll_descriptors_revents. It'll allow to avoid hangs and write data only when audio card is ready for it.

  7. #7
    Just Joined!
    Join Date
    Dec 2012
    Posts
    4
    Hm....the problem is, i'm absolutly nor PCM expert. I'm a good developer, yes, but i've nerver worked with Audio before. And i'm a pure C# developer.

    I took the sources from the Mono project:
    https ://github.com/mono/mono/tree/master/mcs/class/System/System.Media
    and use them in my project.

    Two things i found out:
    https: //github.com/mono/mono/blob/master/mcs/class/System/System.Media/AudioDevice.cs
    When calling "SetFormat" (Line 206) two times, it will not work. Even if both Setformat's have the same arguments. Is there a mistake in the Mono impl?

    "PlaySample" (Line 289) can hang on Line 293. I read some PCM documentation and i'm asking my, wich "****" they do in XRunRecovery. It even seems, the while-loop is not corretc? I'm not sure, i'm not a PCM expert :/

    So i use the classes in the following way:

    var device = new AlsaDevice();
    var wav1 = new WavData(...);
    wav1.Setup(device);
    wav1.play(device);

    works.

    var device = new AlsaDevice();
    var wav1 = new WavData(...);
    wav1.Setup(device);
    wav1.play(device);

    var wav2 = new WavData(...);
    wav2.Setup(device);
    wav2.play(device);

    works not, because 2nd Setup.

    This works:

    var device = new AlsaDevice();
    var wav1 = new WavData(...);
    wav1.Setup(device);
    wav1.play(device);

    var wav2 = new WavData(...);
    wav2.play(device);

    Both wav-Files have exactly the same format (same sample rate, same channels, same ..., only different audio content).

    But some WAV's, i cant play. But i can play them, when i play them "first" or in a special. (and can repeat them). As told, all have the same sample rate and so on.

    Greetings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •