Giter Site home page Giter Site logo

thestk / rtaudio Goto Github PK

View Code? Open in Web Editor NEW
1.4K 1.4K 313.0 2.73 MB

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.

License: Other

CMake 1.41% C++ 64.11% Python 0.49% C 27.55% Shell 0.31% Makefile 0.18% M4 3.51% Go 1.80% Meson 0.64%

rtaudio's People

Contributors

andrewbelt avatar antis81 avatar berkus avatar eclazi avatar elijahr avatar f1xpl avatar garyscavone avatar giuliomoro avatar guidefloripa avatar gvnnz avatar jpcima avatar luzpaz avatar marcustomlinson avatar mcwissink avatar mikedickey avatar mnkisala avatar mvshyvk avatar mycosd avatar neheb avatar ntonnaett avatar nyanpasu64 avatar quicky2000 avatar radarsat1 avatar ryandesign avatar sonoro1234 avatar sreimers avatar tmatth avatar tyounanmoti avatar umlaeute avatar zserge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rtaudio's Issues

Starting a RtAudio app at Linux startup

Hi,

This is not a RtAudio issue but I'm wondering if anyone has already dealt with this problem and what it is the solution.

I have created a init.d script to startup a RtAudio app at startup. I'm having a problem though. Sometimes it is not able to detect the audio device. In this case the audio device is a simple usb audio sound card. It seems that sometimes the device is already present and sometimes it is not.

Thanks in advance. Best regards

Wouldn't it be great to add more C++11 utilities, like std::function or std::mutex?

Recently I had to do a workaround to add custom data (from the stack) to my audio callback.
I had to put it in a single structure and add it via the void *userData parameter in openStream.
I thought of using

using RtAudioCallback = std::function<int(void*, void*, unsigned int, double, RtAudioStreamStatus, void*> instead of the functionptr RtAudioCallback which is

typedef int (*RtAudioCallback)( void *outputBuffer, 
                                                  void *inputBuffer,
                                                  unsigned int nFrames,
                                                  double streamTime,
                                                  RtAudioStreamStatus status,
                                                  void *userData );

This would enable us to use:

RtAudio rtAudio;
Foo foo;
Bar bar;

auto audioCallback = [&](void*, void*, unsigned int, double, RtAudioStreamStatus, void*) 
                                    { return foo.do()+bar.do(); };


rtAudio.openStream(oParam, iParam, format, sampleRate, bufferFrames,
                                  audioCallback, nullptr, options, nullptr);

Pulseaudio in Debian

Hi. Trying to use RtAudio with PulseAudio support in Debian 7.
I have lib-pulse-dev installed in my system but RtAudio's configure script asks for the pulse-simple package. This package does not exist in Debian's repos...
Also If I include RtAudio.cpp (from version 4.1.1 tarball) in my project, define -D__LINUX_PULSE__ and compile, I get the following linker errors:

src/RtAudio.o: In function `RtApiPulse::closeStream()':
RtAudio.cpp:(.text+0xbe): undefined reference to `pa_simple_flush'
RtAudio.cpp:(.text+0xc7): undefined reference to `pa_simple_free'
RtAudio.cpp:(.text+0xd5): undefined reference to `pa_simple_free'
src/RtAudio.o: In function `RtApiPulse::abortStream()':
RtAudio.cpp:(.text+0x1652): undefined reference to `pa_simple_flush'
src/RtAudio.o: In function `RtApiPulse::stopStream()':
RtAudio.cpp:(.text+0x1822): undefined reference to `pa_simple_drain'
src/RtAudio.o: In function `RtApiPulse::callbackEvent()':
RtAudio.cpp:(.text+0x4519): undefined reference to `pa_simple_write'
RtAudio.cpp:(.text+0x46a0): undefined reference to `pa_simple_read'
src/RtAudio.o: In function `RtApiPulse::probeDeviceOpen(unsigned int, RtApi::StreamMode, unsigned int, unsigned int, unsigned int, unsigned long, unsigned int*, RtAudio::StreamOptions*)':
RtAudio.cpp:(.text+0xa24d): undefined reference to `pa_simple_new'
RtAudio.cpp:(.text+0xa346): undefined reference to `pa_simple_new'
collect2: error: ld returned 1 exit status

Any advise on how to get pulse audio support through RtAudio in Debian?

Thanks!

saveDeviceInfo in ASIO

Some ASIO devices are not well behaved and getting their info is a long task.
So getting the info for all ASIO devices when doing openStream on ASIO is too lasting operation.
I would prefer to get an error if I try to get devices info when one of them is already open.

thanks
victor

Start JACK client with input ports, but without any input connection ?

Is it possible to start an input/output stream for JACK without connecting to a particular input stream by default ? I always have to set some device, to which the stream is then automatically connected. But i'd basically like to avoid to connect the client to my microphone input by default ...

I can't figure out any possibility, currently ...

Changed ABI without SONAME bump

RtAudio 4.1 included a change from RtError to RtAudioError. This makes the new library incompatible with binaries built against older versions of the library. For this reason, the MAJOR number should be bumped to 5.

Access to stream with realtime flag is heavily restricted

Hello,
If I open a stream with RTAUDIO_SCHEDULE_REALTIME on Windows with WASAPI,
no external acess is possible.
Word example:

Audio reference for all threads available;
Thread one{

Opens stream with all needed params
}

Thread two{
//If stream is stopped
pushes new data to buffer.
starts the stream again.
}

--> Result is, that the callback function will only work for maximal 2 times!!! So at all, the program is not working right...

Solution:
Deselect realtime flag and access to stream is not restricted any more.

Question:
Is that intended to do so or is that a bug?

PS:
Thanks a lot for this great API 😃 !

Mobile support? iOS/Android

I just wanted to know if there's been any plans for supporting mobile platforms like iOS / Android. I don't mind doing the work, it doesn't seem impossible given the simplicity of RtAudio :)

The plan for iOS is to support CoreAudio directly instead of OpenAL (unless OpenAL could be useful on other platforms). For Android, there is apparently OpenSL. All of those APIs seem to be the low latency options but any other suggestions are welcome.

'functiondiscoverykeys_devpkey.h': No such file or directory

I'm getting this error when compiling for Windows Store App 8.1 (/DWINAPI_FAMILY=WINAPI_FAMILY_APP) with Visual Studio Express 2013 for Windows (but not for Windows Desktop), with WASAPI enabled:

drivers\rtaudio\RtAudio.cpp(3605) : fatal error C1083: Cannot open include file: 'functiondiscoverykeys_devpkey.h': No such file or directory

I'm using the "VS2012 x64 Cross Tools Command Prompt". I'm kinda lost with all these new windows versions, is this the right configuration? From what I understand WASAPI is the one for all the new windows phone/windows app 8.1 stuff?

Thanks!

convertBuffer() is wrong for S24 and ALSA

For 24 bit sample format ALSA uses full 32 bit word and takes only 24 bits of data. In the convertBuffer() you use S24 pointer to iterate buffer and it's wrong for ALSA. For example, lines 9827-9838, there is:
Int24 *in = (Int24 *)inBuffer;
for ALSA you will take only three bytes from input buffer but you should take 4, like this:
Int32 *in = (Int32 *)inBuffer;
and later convert a value to Int24 to extract an integer.
The same in the line 9943, there is:
Int24 *out = (Int24 *)outBuffer;
so you will write 3 bytes of output but for ALSA it should be four. Now it writes only 3/4 of the buffer and the last 1/4 remains untouched. Actually it would be good to memset a buffer with 0 after calloc().

Also, there is no support of big endian formats (in S24 for example) but it should be like 'feature request', not a bug.

WASAPI and MINGW32 4.9.2

Hi,
I cannot build RtAudio with the Mingw compiler version 4.9.2 32 bits under Windows 10.
The same problem exists with the version 4.11 of RtAudio.
At the link phase, 2 errors are generated:

  1. ...\audiotools\RtAudio.cpp:4193: erreur : undefined reference to KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
  2. ..\audiotools\RtAudio.cpp:4204: erreur : undefined reference to KSDATAFORMAT_SUBTYPE_PCM

Probably it is a Mingw problem.
To fix temporarly the problem I add at the function RtAudio::DeviceInfo RtApiWasapi::getDeviceInfo( unsigned int device)

// Define uuid structure due to a problem with Mingw compiler.
// Mingw generates an undefined symbol KSDATAFORMAT_SUBTYPE_FLOAT and KSDATAFORMAT_SUBTYPE_PCM

static IID KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_GCC; // static variable for KSDATAFORMAT_SUBTYPE_IEEE_FLOAT symbol
static IID KSDATAFORMAT_SUBTYPE_PCM_GCC; // static variable for KSDATAFORMAT_SUBTYPE_PCM symbol
static bool KSDATAFORMAT_SUBTYP_INIT = false; // Static variable to initialize once

// Initialize KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_GCC struct
auto KSDATAFORMAT_SUBTYPE_FLOAT_IEEE_INIT = [] ()
{
unsigned char * uuid = (unsigned char * )"00000003-0000-0010-8000-00aa00389b71";
::UuidFromStringA (uuid, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_GCC);
};

// Initialize KSDATAFORMAT_SUBTYPE_PCM_GCC struct
auto KSDATAFORMAT_SUBTYPE_PCM_INIT = [] ()
{
unsigned char * uuid = (unsigned char * )"00000001-0000-0010-8000-00aa00389b71";
::UuidFromStringA (uuid, &KSDATAFORMAT_SUBTYPE_PCM_GCC);
};`

// Initialize once
if (!KSDATAFORMAT_SUBTYP_INIT)
{
KSDATAFORMAT_SUBTYPE_PCM_INIT ();
KSDATAFORMAT_SUBTYPE_FLOAT_IEEE_INIT ();
KSDATAFORMAT_SUBTYP_INIT = true;
}

and replace all references at KSDATAFORMAT_SUBTYPE_IEEE_FLOAT by KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_GCC and KSDATAFORMAT_SUBTYPE_PCM by KSDATAFORMAT_SUBTYPE_PCM_GCC

I validated it on 4.11 version of RtAudio.

Many thanks for this job.
Patrice

Cannot build on windows 10 (Unknown system type for realtime support!)

This is the output when I am running ./configure
I managed to make rtaudio work with visual studio for long time ago, but I can't build it with mingw.

$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... no
checking whether make supports nested variables... no
checking that version numbers are coherent... checking for style of include used by make... none
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... none
yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports nested variables... (cached) no
checking pkg-config... no
checking whether to compile debug version... checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... none
checking for ar... ar
checking the archiver (ar) interface... ar
checking for ar... /c/MinGW/bin/ar
checking build system type... x86_64-pc-mingw64
checking host system type... x86_64-pc-mingw64
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... c:/mingw/mingw32/bin/ld.exe
checking if the linker (c:/mingw/mingw32/bin/ld.exe) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /c/MinGW/bin/nm -B
checking the name lister (/c/MinGW/bin/nm -B) interface... BSD nm
checking whether ln -s works... no, using cp -pR
checking the maximum length of command line arguments... 8192
checking how to convert x86_64-pc-mingw64 file names to x86_64-pc-mingw64 format... func_convert_file_msys_to_w32
checking how to convert x86_64-pc-mingw64 file names to toolchain format... func_convert_file_msys_to_w32
checking for c:/mingw/mingw32/bin/ld.exe option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... file_magic ^x86 archive import|^x86 DLL
checking for dlltool... dlltool
checking how to associate runtime and link libraries... func_cygming_dll_for_implib
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /c/MinGW/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for as... as
checking for dlltool... (cached) dlltool
checking for objdump... (cached) objdump
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -DDLL_EXPORT -DPIC
checking if gcc PIC flag -DDLL_EXPORT -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (c:/mingw/mingw32/bin/ld.exe) supports shared libraries... yes
checking whether -lc should be explicitly linked in... yes
checking dynamic linker characteristics... Win32 ld.exe
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... c:/mingw/mingw32/bin/ld.exe
checking if the linker (c:/mingw/mingw32/bin/ld.exe) is GNU ld... yes
checking whether the g++ linker (c:/mingw/mingw32/bin/ld.exe) supports shared libraries... yes
checking for g++ option to produce PIC... -DDLL_EXPORT -DPIC
checking if g++ PIC flag -DDLL_EXPORT -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (c:/mingw/mingw32/bin/ld.exe) supports shared libraries... yes
checking dynamic linker characteristics... Win32 ld.exe
checking how to hardcode library paths into programs... immediate
checking for ANSI C header files... (cached) yes
checking sys/ioctl.h usability... no
checking sys/ioctl.h presence... no
checking for sys/ioctl.h... no
checking for unistd.h... (cached) yes
checking for gettimeofday... yes
checking for doxygen... no
checking for audio API... configure: error: Unknown system type for realtime support!

Rare segmentation fault due to jackStopStream race condition

Hello! First of all, thanks so much for RtAudio! I've been using it with Jack (via Cadence), and I've found that once in a blue moon, I get a segmentation fault, whick kinda throws a wrench in things. Do you know what might be going on here?

Regards,
T.

Backtrace:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./beaver'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 sem_timedwait_cleanup () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S:306

306 ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: No such file or directory.
(gdb) info threads
Id Target Id Frame
3 Thread 0x7f73f7139700 (LWP 19421) 0x00007f73ff34866b in pthread_join (threadid=140136185153280, thread_return=0x7f73f7138e38) at pthread_join.c:92
2 Thread 0x7f73ff998780 (LWP 19411) 0x00007f73fe024587 in munmap () at ../sysdeps/unix/syscall-template.S:81

  • 1 Thread 0x7f73ff894700 (LWP 19420) (Exiting) sem_timedwait_cleanup () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S:306
    (gdb) thread apply all bt

Thread 3 (Thread 0x7f73f7139700 (LWP 19421)):
#0 0x00007f73ff34866b in pthread_join (threadid=140136185153280, thread_return=0x7f73f7138e38) at pthread_join.c:92
#1 0x00007f73ff58c009 in ?? () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#2 0x00007f73ff56e80c in ?? () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#3 0x000000000040ab03 in RtApiJack::stopStream (this=0x1fb6c40) at RtAudio.cpp:2462
#4 0x000000000040abcd in jackStopStream (ptr=0x2006b30) at RtAudio.cpp:2492
#5 0x0000000001fb6e68 in ?? ()
#6 0x0000000001fb6e68 in ?? ()
#7 0x0000000001fb6c40 in ?? ()
#8 0x0000000000000000 in ?? ()

Thread 2 (Thread 0x7f73ff998780 (LWP 19411)):
#0 0x00007f73fe024587 in munmap () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007f73ff58eeef in jack_client_close () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#2 0x000000000040a580 in RtApiJack::closeStream (this=0x1fb6c40) at RtAudio.cpp:2343
#3 0x0000000000404947 in RtAudio::getDefaultInputDevice (this=0x7fffdf6d1400) at RtAudio.h:829
#4 0x00000000004043a8 in main () at beaver.cpp:311

Thread 1 (Thread 0x7f73ff894700 (LWP 19420)):
#0 sem_timedwait_cleanup () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S:306
#1 0x00007f73ff58c94c in ?? () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#2 0x00007f73ff570fec in ?? () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#3 0x00007f73ff57019f in ?? () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#4 0x00007f73ff56f8e8 in ?? () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#5 0x00007f73ff58bb70 in ?? () from /usr/lib/x86_64-linux-gnu/libjack.so.0
#6 0x00007f73ff347182 in start_thread (arg=0x7f73ff894700) at pthread_create.c:312
#7 0x00007f73fe02a00d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

(gdb)

stream_.lastTickTimestamp not initialized

Hi,

Calling in sequence:

dac:openStream(...
dac:setStreamTime(10) <- set to whatever different from 0
dac:getStreamTime() -> gives 10
dac:startStream()
dac:getStreamTime() -> gives whatever

this is because stream_.lastTickTimestamp is still not initialized when second getStreamTime is called
the first getStreamTime is OK because

 if ( stream_.state != STREAM_RUNNING || stream_.streamTime == 0.0 )
    return stream_.streamTime;

not sure about how could this be fixed

Best Regards
victor bombi

PulseAudio playback stream name

As long as "Record" supports streamName parameter "Playback" is not.
Any PulseAudio GUI displays then
Record:AppName and Playback:RtAudio
Small thing but maybe.

Here is a patch:

diff -r a0f06e0ef24e src/libs/sound/rt/RtAudio.cpp
--- a/src/libs/sound/rt/RtAudio.cpp Wed Apr 08 11:00:37 2015 +0200
+++ b/src/libs/sound/rt/RtAudio.cpp Thu Apr 09 11:48:15 2015 +0200
@@ -8499,7 +8499,7 @@
}
break;
case OUTPUT:

  • pah->s_play = pa_simple_new( NULL, "RtAudio", PA_STREAM_PLAYBACK, NULL, "Playback", &ss, NULL, NULL, &error );
  • pah->s_play = pa_simple_new( NULL, streamName.c_str(), PA_STREAM_PLAYBACK, NULL, "Playback", &ss, NULL, NULL, &error );
    if ( !pah->s_play ) {
    errorText_ = "RtApiPulse::probeDeviceOpen: error connecting output to PulseAudio server.";
    goto error;

make install fails (mingw)

make install fails when run in windows using mingw (msys). It's presumably caused by the install documentation file (also called install) clashing with the install command; when I rename this file everything works as expected.

Split RtAudio.cpp into multiple files

As of writing this, RtAudio.cpp has 10230 lines, and as far as I can tell, it's the only source file which makes up RtAudio itself.
I'm sure this makes it very difficult to navigate (it definitely did for me), so wouldn't splitting it into multiple files, say, by class make it nicer to work with?

configure cannot find libpulse-simple

RtAudio 4.1.1 on Ubuntu 14.04. Configure scripts says

$ ./configure --with-jack --with-alsa --with-pulse
[...]
using PulseAudio
checking PULSE... no
configure: error: PulseAudio support requires the pulse-simple library!

While pulse-simple is correctly installed in the system:

$ locate pulse-simple
/usr/lib/x86_64-linux-gnu/libpulse-simple.so
/usr/lib/x86_64-linux-gnu/libpulse-simple.so.0
/usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.0.4
/usr/lib/x86_64-linux-gnu/pkgconfig/libpulse-simple.pc
$ pkg-config --list-all | grep libpulse-simple
libpulse-simple           libpulse-simple - PulseAudio Simplified Synchronous Client Interface

stream time is faster than right time when use RtAudio::Api::WINDOWS_WASAPI

stream time is faster than right time when use RtAudio::Api::WINDOWS_WASAPI, but use RtAudio::Api::WINDOWS:DS is right, HERE IS MY CODE:

include "stdafx.h"

include "RtAudio.h"

typedef struct playback_s
{
HANDLE handle;
WAVEFORMATEX* pWfx;
RtAudio* pAudio;
} playback_t;

DWORD readChunk(HANDLE hFile, void* buf, size_t size)
{
DWORD readByes;
if (ReadFile(hFile, buf, size, &readByes, NULL) == FALSE)
return 0;

return readByes;

}

int saw(void outputBuffer, void * inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *data)
{
playback_t
playback = reinterpret_cast<playback_t*>(data);
DWORD dwReadBytes = 0;
BOOL ret = FALSE;

ret = ReadFile(playback->handle, outputBuffer, nBufferFrames * playback->pWfx->nBlockAlign, &dwReadBytes, NULL);
if (ret == FALSE || dwReadBytes == 0)
    return 1;

return 0;

}

int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile;
WAVEFORMATEX wfx;
char riff[5], wave[5], fmt[5], data[5];
DWORD len, struct_len, data_len;

TCHAR* pszFile = _T("D:\\Music\\Love Story.wav");
if ((hFile = CreateFile(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
{
    _tprintf(_T("%s: unable to open file '%s'\n"), argv[0], pszFile);
    ExitProcess(1);
}

//check file is a wav file
readChunk(hFile, (void*)riff, 4);
riff[4] = '\0';
if (strncmp(riff, "RIFF", 4) == 0)
{
    _tprintf(_T("file '%s' is a wave file.\r\n"), pszFile);

    readChunk(hFile, (void*)&len, 4);
    readChunk(hFile, (void*)wave, 4);
    readChunk(hFile, (void*)fmt, 4);
    readChunk(hFile, (void*)&struct_len, 4);
    readChunk(hFile, (void*)&wfx, struct_len);
    readChunk(hFile, (void*)data, 4);
    readChunk(hFile, (void*)&data_len, 4);
}
else
{
    _tprintf(_T("file '%s' is a raw file.\r\n"), pszFile);
    SetFilePointer(hFile, 0, NULL, FILE_BEGIN);

    wfx.nSamplesPerSec = 44100;
    wfx.wBitsPerSample = 16;
    wfx.nChannels = 2;
    wfx.cbSize = 0;
    wfx.wFormatTag = WAVE_FORMAT_PCM;
    wfx.nBlockAlign = (wfx.wBitsPerSample * wfx.nChannels) >> 3;
    wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
}

printf("WAVEFORMATEX.wFormatTag=%d\r\n", wfx.wFormatTag);
printf("WAVEFORMATEX.nChannels=%d\r\n", wfx.nChannels);
printf("WAVEFORMATEX.nSamplesPerSec=%d\r\n", wfx.nSamplesPerSec);
printf("WAVEFORMATEX.nAvgBytesPerSec=%d\r\n", wfx.nAvgBytesPerSec);
printf("WAVEFORMATEX.nBlockAlign=%d\r\n", wfx.nBlockAlign);
printf("WAVEFORMATEX.wBitsPerSample=%d\r\n", wfx.wBitsPerSample);

RtAudio audio(RtAudio::Api::WINDOWS_WASAPI);

try
{
    RtAudio::StreamParameters param;
    param.deviceId = audio.getDefaultOutputDevice();
    param.nChannels = wfx.nChannels;
    param.firstChannel = 0;

    unsigned int bufferSize = 1024;

    RtAudioFormat format = 0;
    switch (wfx.wBitsPerSample)
    {
    case 8:
        format = RTAUDIO_SINT8;
        break;
    case 16:
        format = RTAUDIO_SINT16;
        break;
    case 24:
        format = RTAUDIO_SINT24;
        break;
    case 32:
        format = RTAUDIO_SINT32;
        break;
    }

    playback_t playback;
    playback.handle = hFile;
    playback.pWfx = &wfx;
    playback.pAudio = &audio;

    RtAudio::StreamOptions options;
    options.flags = RTAUDIO_HOG_DEVICE | RTAUDIO_SCHEDULE_REALTIME | RTAUDIO_MINIMIZE_LATENCY;

    audio.openStream(&param, NULL, format, wfx.nSamplesPerSec, &bufferSize, (RtAudioCallback)saw,
        (void*)&playback, &options, NULL);
    printf("bufferSize=%d\n", bufferSize);

    audio.startStream();
}
catch (RtAudioError& e)
{
    e.printMessage();
    goto exit;
}

while (audio.isStreamRunning())
{
    printf("latency=%ld, time=%3.2f\n", audio.getStreamLatency(), audio.getStreamTime());
    Sleep(50);
}

try
{
    if (audio.isStreamOpen())
        audio.stopStream();
}
catch (RtAudioError& e)
{
    e.printMessage();
}

exit:
if (audio.isStreamOpen())
audio.stopStream();

CloseHandle(hFile);
return 0;

}

Location of distributed headers on Linux (Unix?)

At least for Debian, header files (there's only one, right?) seem to be packaged falsely and apt install librtaudio-dev copies to /usr/include/RtAudio.h. On Arch linux OTOH files are installed to /usr/include/rtaudio/RtAudio.h. Could you please check and fix that? If you ask me, the "rtaudio" prefix is the right thing to do. Probably headers can be symlink'ed RtAudio.h -> rtaudio/RtAudio.h to keep backwards compatibility, though I wouldn't advice that and rather help people to get cross-compatibile code.

.lib file not generated with .dll using CMake and Visual Studio 2015

I'm building a .dll for RtAudio, so I've generated a VS2015 project with CMake and compiled the project in all build modes. The static builds work fine, but the .dll files are being generated without an accompanying .lib file. The Release and RelWithDebInfo modes build a 16KB .dll file, so I assume nothing is being included in those files. I'm not well-versed in Windows, but are the symbols/functions not being exported?

WASAPI: when using non-default sample rates or disagreeing channel counts, all tests are silent

The title pretty much says it all. In WASAPI, if operating in shared mode, you have to use the same channel count and sample rate as the device is set/configured to. Exclusive mode will give some more flexibility, but not much; if Rtaudio uses exclusive mode exclusively, I won't be able to use it because it blocks out pretty much all forms of assistive technology that provide audio feedback (any app not written to "play nice" in the case of exclusive mode doesn't get audio). Also, exclusive mode support can be turned off by the user, anyway.
I've not looked super closely yet, but suspect that it's a simple matter of getting a resampler hooked in between the Rtaudio API and the stream. I'm not too sure what to do about channel counts; I'd expect an error in this case, but I'm not sure what level of abstraction Rtaudio aims to provide and will consequently leave any such decisions about it to others.

CallbackInfo constructor warnings

Hi,
the constructor of callbackinfo is not complete.

Member 'priority' was not initialized in this constructor

I just wanted to notice this, cause I learned it's not ok to have any warnings in the program.

Build problem with MSYS2 + MinGW

Hi,

I've tried to compile RtAudio with MSYS2 + MinGW, but I got these errors:

/rtaudio/RtAudio.cpp:3878:73: error: 'roundf' was not declared in this scope outSampleCount = ( unsigned int ) roundf( inSampleCount * sampleRatio );

/rtaudio/tests/duplex.cpp:58:3: error: 'uint32_t' was not declared in this scope uint32_t *bytes = (uint32_t *) data;

It turned out that to solve easily these errors (without changes the code) it is enough to add -std=c++11 to the CMAKE_CXX_FLAGS

Anyway I think it would be better to include the right headers.

System information:
OS: Windows 7 SP1 64bit
MSYS2 with the following package installed: mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb git vim make mingw-w64-x86_64-cmake-git mingw-w64-x86_64-pkgconf

How to perform input/output syncing

I dared to put a question here, sorry if it is not good place but seems to be the only place....

I have problems with synchronization of input and output devices in duplex mode when they are different.
Problems occur either with my app and with duplex test.
After while (10-20s) of properly forwarding input to output some glitches are audible (like trrrrr :-) ).
Buffer size is set to 512 or 1024 (it makes no difference)
Interesting is a fact that it occurs under Linux ALSA but with PulseAudio it works well.
Also under Windows (7) WASAPI gives glitches but DirectSounds and ASIO not (In ASIO case set stream option flag to RTAUDIO_MINIMIZE_LATENCY helped).

It seems like sound servers (WASAPI seems to imitate DS) take care about syncing but working on "raw" devices moves responsibility on developer. (I'm guessing this)

Is it difficult to sync?

duplex vs two threads - and what does RTAUDIO_HOG_DEVICE mean?

Hi

I'm interested in writing a digital crossover. I'm typing while I play with a duplex open on my soundcard that delegates buffers to a background thread. There are some 'zero' buffers in the system to start with, so processing those is supposed to hide scheduling latencies for the worker thread (and compute, I'm interested in FIR as well as IIR). It seems to be working, albeit on passthrough currently. (And I'm rather enjoying Enya's new album, actually)

Anyway - while I ponder using lockfree queues instead of the std::mutex/std::condition stuff I have now, I wonder if there is any practical improvement to be had with dedicated threads running the input and output, vs a duplex open. I'm using a single soundcard, so I have a coherent sample clock either way. The CPU has multiple cores. I'm aware (well, guessing) that the rtaudio upcall is in some sense driven from the card clock, while other threads are running from the OS scheduler.

I (very occasionally) get a click - I'm assuming that this is from the duplex thread getting thrown off the CPU when trying to pull a chunk for output - its just acquiring a std::mutex while it does so, and potentially broadcasting on a condition.

I'm inclined to use RTAUDIO_HOG_DEVICE - the comment says 'Attempt grab device and prevent use by others.' but does it defend against other applications, or would an input-only stream with HOG prevent the same process opening output?

(Currently running on Win10 with ASIO, but I'd like to be able to work against native audio, and later compile to run on raspberry pi, albeit output only - which suggests to me that a twin thread system would work better - so there is some benefit from leaving the duplex arrangement I'm listening to).

Nice library, anyway.

RtAudio.cpp needs to include more headers for DirectSound

In certain cases (an MFC app building on Windows 10), RtAudio.cpp pulling in dsound.h (platform copy, as it should be), will fail build.

The solution is to add:

#include "mmsystem.h"
#include "mmreg.h"

immediately before the line:

#include <dsound.h>

I am also aware there is another thread about distributing dsound.h. I don't care about the legal aspect, but it's probably a bad idea. When/if things go wrong, a user will not immediately know which dsound.h was pulled in, especially because <> are used instead of "".

Can't build in Linux

Autoconf make no errors,

./autogen.sh --with-alsa --with-jack --with-pulse

but then make says,

RtAudio.cpp:1943:13: error: 'void jackSilentError(const char*)' defined but not used [-Werror=unused-function]
static void jackSilentError( const char * ) {};
cc1plus: all warnings being treated as errors

I am doing something wrong apparently

Thanks in advance

ASIO SDK version

Hello, I'm new to RtAudio world, i'm having a test on it for a real-time audio processing application on Mac and Windows.

I saw that version 2.1 of ASIO SDK comes with the library, current version from steinberg is 2.3, is there a special reason to use 2.1 ? It's just a question not a query, if it's just a matter of time, perhaps I could help when my knowledge is sufficient.

Thanks a lot for your work.

ALSA duplex mode mono output has unintentional passthrough

If I use ALSA in duplex mode and request 1 output channel, my device reports 2 as minimum number of channels, rtaudio swallows this, and I'm guessing because of some memory mismanagement, I get a passthrough from mic to speaker even when my callback only returns 0.

What does this comment mean?
https://github.com/thestk/rtaudio/blob/master/RtAudio.cpp#L7418
"Determine the number of channels for this device. We support a possible minimum device channel number > than the value requested by the user."
The blame for the line points to this commit, which I don't know how to dissect further:
6faf433

Anyway, in particular, what does "support" mean? Is there any test? Is what I observed actually expected? I'm happy to tromp through the code for an error -- if you think there is one.

WASAPI: when using non-default sample rates, there are audio artifacts

Affects RtAudio 4.1.2

There appears to be very crude resampling of waveforms when the selected sample rate for the output stream doesn't match the default sample rate of the device. I have tested this on Windows 7, 8 & 10.

Here is an example waveform, captured via loopback, where the selected sample rate is 44100Hz and the default sample rate is 48000Hz. The red arrows indicate the "extra" samples that appear to have been added to achieve resampling and which result in significant audio artifacts.

screen shot 2016-07-29 at 15 20 34

Possibly related to #22 ?

setStreamTime?

I am working on a lua wrapping of RtAudio.
I think it is quite complete but also simple, congratulations!!!

getStreamTime gives the time it has been playing from the first startStream.
this behaviour is ok for startStream and stopStream but makes difficult to implement a stream time navigation (may be a slider to change time position in a stream)
I think setStreamTime would be perfect for that.

Best Regards
victor bombi

Include <algorithm> for VC++2013 compatibility

When building on VC++2013, std::max needs to be obtained by including algorithm. If not included, Rtaudio won't build.
Not sure what other windows headers might offer std::max, but is the one I always use.

Supported deviceInfo.nativeFormats seems not correct using WINDOWS_WASAPI.

Hi,
When using WINDOWS_WASAPI api, getDeviceInfo function returns the value 16 for nativeFormats. This means that only RTAUDIO_FLOAT32 is supported. I try also RTAUDIO_SINT8, RTAUDIO_SINT16, RTAUDIO_SINT24, RTAUDIO_SINT32. Its run perfectly on my laptop.

In the same way, using WINDOWS_DS, getDeviceInfo function returns the value 3 for nativeFormats. This means that only RTAUDIO_SINT8 and RTAUDIO are supported. I check RTAUDIO_FLOAT32 on my laptop, it runs well.
RtAudio version tested:4.1.2.

Distorted audio on simple ASIO loop through

Hello -

I am currently testing RtAudio in hopes to use it on a project, and am getting unexpected results!

Given my code below (hooked up to a known-good ASIO device), I would expect my output to be essentially a copy of my input; that said it is very distorted and only somewhat recognizable with all the static / noise. Using Audacity or other known-good software I can run the same test on my hardware with no audible problems.

My setup is very simple:

audioDriver->openStream(&parameters, &parameters, RTAUDIO_SINT16, sampleRate, &bufferFrames, &input, NULL, &options);
audioDriver->startStream();

And my callback is very simple too:

int input(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *userData)
{
if (status)
std::cout << "input: " << status << std::endl;
memcpy(outputBuffer, inputBuffer, nBufferFrames);
return 0;
}

Any insight you could offer would be so appreciated!! Sorry if this is the wrong place to post a question / issue of this nature.

Kind Regards,

  • James Heliker

Wrong order when calling CoUninitialize () in RtAudio.cpp

`RtApiDs :: ~RtApiDs()
{
if ( coInitialized_ ) CoUninitialize(); // balanced call.
if ( stream_.state != STREAM_CLOSED ) closeStream();
}

`
According to documentation, CoUninitialize() must be "the last call made to the COM library". After this, the entire COM world may be broken. So, closeStream() may leak or even crash under some circumstances. I believe the correct version is

`RtApiDs :: ~RtApiDs()
{
if ( stream_.state != STREAM_CLOSED ) closeStream();
if ( coInitialized_ ) CoUninitialize(); // balanced call.
}

`

JACK doesn't respect data format

I noticed that in some cases JACK doesn't start stream with data format different than FLOAT32.
The "cases" occurred when JACK was run in 48000Hz samplerate.
When it was run in 44100Hz, supportedFormats() method returned FLOAT32 and INT16 as well but with 480000 only FLOAT32 was there and stream didn't initialise with INT16.
It happened under Linux.

I didn't test JACK under Mac but there, with coreAudio, supportedFormats() returns only FLOAT32 but RtAudio starts nicely with INT16 and converts it silently.

include_directories needed

I was trying to compile RtAudio for the Raspberry PI. The compiler complained about not finding the alsa/asound.h include file.

I'm not sure if this is needed for another Linux distributions, but I had to include the ALSA_INCLUDE_DIRs at the end of the main CMakeList.txt file like this:

include_directories(rtaudio ${ALSA_INCLUDE_DIR})

Add payload (userData) in error callback

Hey,

I'm implementing a Qt-wrapper and Qt consequently disables exception handling. Thus, most RtAudio examples won't even compile with that - like in the device settings example:

#include "RtAudio.h"
int main()
{
  RtAudio dac;
  if ( dac.getDeviceCount() == 0 ) exit( 0 );
  RtAudio::StreamParameters parameters;
  parameters.deviceId = dac.getDefaultOutputDevice();
  parameters.nChannels = 2;
  unsigned int sampleRate = 44100;
  unsigned int bufferFrames = 256; // 256 sample frames
  RtAudio::StreamOptions options;
  options.flags = RTAUDIO_NONINTERLEAVED;
  try {
    dac.openStream( &parameters, NULL, RTAUDIO_FLOAT32,
                    sampleRate, &bufferFrames, &myCallback, NULL, &options );
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    exit( 0 );
  }

  return 0;
}

I assume to set a bool isOpen member variable depending on the success of the dac.openStream function call. As there is no error return value, I don't see a chance other than to pass this as userData to the RtAudioErrorCallback - which is not possible. Thus, I'm somewhat stuck.

Questions:

  1. If exceptions have to be enabled, can I achieve that only for RtAudio?
  2. Is there a way to use RtAudio without exceptions?

Btw. passing a C++11/14 lambda would also work fine, if the context could be passed along with it. I.e. something like this:

a.openStream(…, [&](RtAudioError::Type t, const std::string& msg) { 
    this->mIsOpen = false; 
    std::cerr << msg;
});

linking WASAPI mingw

building with mingw and wasapi support says:

CMakeFiles\RtAudio.dir/objects.a(RtAudio.cpp.obj):RtAudio.cpp:(.text+0xb532): undefined reference to KSDATAFORMAT_SUBTYPE_IE EE_FLOAT' CMakeFiles\RtAudio.dir/objects.a(RtAudio.cpp.obj):RtAudio.cpp:(.text+0xb551): undefined reference toKSDATAFORMAT_SUBTYPE_PC
M'

RtAudio::openStream Crash on Linux with PulseAudio

I do the following :

RtAudio audio(RtAudio::LINUX_PULSE);
StreamParameters parameters;

parameters.deviceId = audio.getDefaultOutputDevice();
parameters.nChannels = 2; // Checked that this was correct by printing the info
parameters.firstChannel = 0;
unsigned int frames = 1024;
audio.openStream( &parameters,
                                  nullptr,
                                  RTAUDIO_FLOAT32,
                                  44100,
                                  &frames,
                                  &generate_sound);

But I get a segfault in :

RtApiPulse::probeDeviceOpen(unsigned int, RtApi::StreamMode, unsigned int, unsigned int, unsigned int, unsigned long, unsigned int *, RtAudio::StreamOptions *)

Here is the memory content of audio.getDeviceInfo(audio.getDefaultOutputDevice()); :

info    @0x7fffffffe060 RtAudio::DeviceInfo
    duplexChannels  2   unsigned int
    inputChannels   2   unsigned int
    isDefaultInput  true    bool
    isDefaultOutput true    bool
    name    "PulseAudio"    std::string
    nativeFormats   26  RtAudioFormat
    outputChannels  2   unsigned int
    probed  true    bool
    sampleRates <7 éléments>  std::vector<unsigned int>

What might I be doing wrong ?

rtaudio/include/dsound.h

Is this file actually redistributable?

I was surprised to find it. Windows SDk is free, isn't it appropriate to have that as a prerequisite?

Supported deviceInfo.sampleRates seems not correct using WINDOWS_DS.

Hi,
It seems that deviceInfo.sampleRates is not correct using WINDOWS_DS.
On my laptop, for WINDOWS_DS api, the function getDeviceInfo returns samples rates from 4000 to 192000.
If I used a sample rate greater than 48000, the sound is distorded.
RtAudio version tested:4.1.2
Patrice

Non-interleaved buffer performance

Hi Gary,

I have a small question :
Is there extra treatments when using non-interleaved buffers on each platform ?

Thank you very much.

Alsa default is somthing inpredictable

When stream is opened with RTAUDIO_ALSA_USE_DEFAULT flag it is impossible to guess what device exactly was opened - returned reference to StreamParaameters doesn't correspond to real state. Also buferFrames value is forced by this "default" device.
Any clue from RtAudio is necessary to determine which device it is among devices list and to able to open it without "default" when all parameters are manageable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.