Thread: Need to interact with sound card

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    8

    Need to interact with sound card

    Hello,

    I need to interact with my sound card using an ANSI C program such that I can capture the sound cards output and then manipulate the capture and send it back to the sound cards input for playback. I have been trying to get the portaudio(www.portaudio.com) libraries to compile so it could serve as my API to the sound card. Is this the best code library for this purpose or would you recommend using something else?

    So now the specifics of the current issue I am seeing with using portaudio. I was able to successfully able to install v18 of portaudio using MinGW/MSYS on my windows XP machine. Unfortunately that did not solve the undefined reference error I show below, when trying to work through the portaudio tutorial. I have done some searching in an effort to resolve this but to no avail. I have tried to make sure the .c file I wanted to compile(see below error message) was in the same directory as my portaudio.h file(and I've tried this with both the .c and .h under pa_common, MinGW, and /usr/local/include). I always get the same error though. I have also tried use -L 'path to portaudio.' and -lportaudio but I always get a "cannot find -lportaudio" when using -lportaudio. Is there something obvious I'm missing? I wouldn't be suprised since its been years since I worked in Unix and C. Any feedback is greatly appreciated.

    Thanks,
    Brian

    /usr/local/include
    $ gcc basictest.c -o basictest
    C:/DOCUME~1/BRIAN~1/LOCALS~1/Temp/cc1GI8mn.o:basictest.c.text+0x2b): undefined reference to `Pa_Initialize'
    C:/DOCUME~1/BRIAN~1/LOCALS~1/Temp/cc1GI8mn.o:basictest.c.text+0x33): undefined reference to `Pa_Terminate'
    C:/DOCUME~1/BRIAN~1/LOCALS~1/Temp/cc1GI8mn.o:basictest.c.text+0x75): undefined reference to `Pa_GetErrorText'
    collect2: ld returned 1 exit status

    basictest.c

    Code:
    #include <stdio.h>
    #include "portaudio.h"
    
    main () {
    
    PaError err;
    
    err = Pa_Initialize();
    if( err != paNoError) goto error;
    
    error:
        Pa_Terminate();
        fprintf( stderr, "An error occured while using the portaudio stream\n" );
        fprintf( stderr, "Error number: %d\n", err );
        fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
        return err;
    
    }

  2. #2
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    If -lportaudio is not found, then the .lib file is not in the correct directory, e.g. portaudio is not installed correctly.

    Reinstall portaudio, and link with -lportaudio, and you should be good.

    The reason you're getting those errors is because you're not linking with the portaudio library.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  3. #3
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    Quote Originally Posted by Nightowl View Post
    If -lportaudio is not found, then the .lib file is not in the correct directory, e.g. portaudio is not installed correctly.

    Reinstall portaudio, and link with -lportaudio, and you should be good.

    The reason you're getting those errors is because you're not linking with the portaudio library.
    Oh and since you brought that up, note to the OP, MinGW uses .a, not .lib, so a conversion might be in place. Depends what all comes packaged with the library.

  4. #4
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    Oh, good point. MinGW always confuzzles me for some reason . . .
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Quote Originally Posted by Nightowl View Post
    If -lportaudio is not found, then the .lib file is not in the correct directory, e.g. portaudio is not installed correctly.

    Reinstall portaudio, and link with -lportaudio, and you should be good.

    The reason you're getting those errors is because you're not linking with the portaudio library.
    Right this seems to make sense based on what I understand, have read. However I'm not perfectly clear on how to correct it. Maybe if I tell you exactly what I did to install portaudio the first time you could help me figure out what to do different next time. Here are the steps I followed to install v18, I tried v19 first but had many problems which others seemed to be having also so reverted to v18.

    Steps;

    1) downloaded portaudio_v18_1.zip, from http://www.portaudio.com/download.html and extracted it.

    2) followed the instructions here for compiling in windows; http://www.portaudio.com/trac/wiki/T...e/WindowsMinGW. In MSYS I went to the directory of the configure file( /c/portaudio/portaudio_v18_1/portaudio_v18_1)then executed './configure' followed by 'make' then 'make install'. The first time 'make install' failed because it could not put a file in /usr/local/lib or /usr/local/include because those directories did not exist. I created those directories and exectued 'make install', it said that portaudio was sucessfully installed.

    Do you see anything I should do differently if I was to do this again? Are there any restrictions around where I can have all of my WinGW/MSYS stuff Vs my .c code file Vs the portaudio files? Do I need to regsvr32 the dll that gets created? Just tried that but I'm getting an DllRegisterServer entry point was not found. Thanks again for your help!
    Last edited by SubtleAphex; 03-19-2009 at 10:42 PM.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Quote Originally Posted by carrotcake1029 View Post
    Oh and since you brought that up, note to the OP, MinGW uses .a, not .lib, so a conversion might be in place. Depends what all comes packaged with the library.
    I started following this lead this morning and thought I was onto something when I found this page about how MinGW uses or doesn't use "unix-style" directories; http://www.mingw.org/wiki/IncludePathHOWTO. The basic summary is that MinGW doesn't search /usr/local/lib or /usr/local/include which is where the installation of my external library(portaudio) puts its files.

    That seemed to be very helpful information but alas I still get the same undefined reference to `Pa_Initialize' error after copying the files from /usr/local/lib to C:\MinGW\lib and from /usr/local/include to C:\MinGW\include. I will put the entire output from my compile commands below.

    Getting back to the fact that MinGW uses .a Vs .lib files, could this still be causing a problem? I would think that now that I moved the libportaudio.a file to C:\MinGW\lib it should be ok. In fact as you will see below when I use the -lportaudio command in my compile line it no longer complains that it can't find -lportaudio, I take that as a good sign.

    Does anyone have a suggestion for what to check next? I might also try using Cgywin as my compiler. Thanks in advance.

    Brian

    /c/mingw/include
    /c/mingw/include
    $ gcc -v -lportaudio basictest.c -o basictest
    Reading specs from c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
    Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
    Thread model: win32
    gcc version 3.4.5 (mingw-vista special r3)
    c:/MinGW/bin/../libexec/gcc/mingw32/3.4.5/cc1.exe -quiet -v -iprefix c:\MinGW\bin\../lib/gcc/mingw32/3.4.5/ basictest.c -quiet -dumpbase basictest.c -auxbase basictest -version -o C:/DOCUME~1/BRIANG~1/LOCALS~1/Temp/ccBRVZkk.s
    ignoring nonexistent directory "c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/include"
    ignoring nonexistent directory "/mingw/lib/gcc/mingw32/3.4.5/../../../../mingw32/include"
    #include "..." search starts here:
    #include <...> search starts here:
    c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include
    c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/include
    /mingw/lib/gcc/mingw32/3.4.5/../../../../include
    /mingw/include
    /mingw/lib/gcc/mingw32/3.4.5/include
    /mingw/include
    End of search list.
    GNU C version 3.4.5 (mingw-vista special r3) (mingw32)
    compiled by GNU C version 3.4.5 (mingw-vista special r3).
    GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129785
    c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/bin/as.exe -o C:/DOCUME~1/BRIANG~1/LOCALS~1/Temp/ccoIuhFQ.o C:/DOCUME~1/BRIANG~1/LOCALS~1/Temp/ccBRVZkk.s
    c:/MinGW/bin/../libexec/gcc/mingw32/3.4.5/collect2.exe -Bdynamic -o basictest.exe /mingw/lib/crt2.o c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/crtbegin.o -Lc:/MinGW/bin/../lib/gcc/mingw32/3.4.5 -Lc:/MinGW/bin/../lib/gcc -L/mingw/lib/gcc/mingw32/3.4.5 -Lc:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib -L/mingw/lib/gcc/mingw32/3.4.5/../../../../mingw32/lib -L/mingw/lib -Lc:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../.. -L/mingw/lib/gcc/mingw32/3.4.5/../../.. -lportaudio C:/DOCUME~1/BRIANG~1/LOCALS~1/Temp/ccoIuhFQ.o -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/crtend.o
    C:/DOCUME~1/BRIANG~1/LOCALS~1/Temp/ccoIuhFQ.o:basictest.c.text+0x2b): undefined reference to `Pa_Initialize'
    C:/DOCUME~1/BRIANG~1/LOCALS~1/Temp/ccoIuhFQ.o:basictest.c.text+0x33): undefined reference to `Pa_Terminate'
    C:/DOCUME~1/BRIANG~1/LOCALS~1/Temp/ccoIuhFQ.o:basictest.c.text+0x75): undefined reference to `Pa_GetErrorText'
    collect2: ld returned 1 exit status
    Last edited by SubtleAphex; 03-20-2009 at 09:55 AM.

  7. #7
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    Well, I decided to compile portaudio myself in Microsoft Visual Studio. It gave me a .lib and a .dll, which I then used in a project. I used your code, and it ran smoothly. Then I converted the .lib to a .a and put it in my MinGW lib directory. I linked it and got the same errors you did, about those 3 functions being undefined. I'm a bit rusty when it comes to MinGW, I usually use VS.

    So in other words, I have the library working in VS, but not working in MinGW.
    Last edited by carrotcake1029; 03-20-2009 at 12:01 PM.

  8. #8
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Quote Originally Posted by carrotcake1029 View Post
    Well, I decided to compile portaudio myself in Microsoft Visual Studio. It gave me a .lib and a .dll, which I then used in a project. I used your code, and it ran smoothly. Then I converted the .lib to a .a and put it in my MinGW lib directory. I linked it and got the same errors you did, about those 3 functions being undefined. I'm a bit rusty when it comes to MinGW, I usually use VS.
    Interesting. Could you provide me with a few more details around how you were able to get a successful compilation from VS? I tried using VS-2005 following these directions this morning; http://www.portaudio.com/trac/wiki/T...ompile/Windows, I also read the readme.txt and the ASIO-README.txt under; portaudio\src\hostapi\asio. After reading those this is exactly what I did;

    1)Extracted v19 of portaudio from pa_stable_v19_20071207.tar

    2) Downloaded ASIO-SDK from Steingberg and put it here; portaudio\src\hostapi\asio. Extracted it. So now I have this directory structure;
    \portaudio\src\hostapi\asio\asiosdk2.2\ASIOSDK2\co mmon
    \portaudio\src\hostapi\asio\asiosdk2.2\ASIOSDK2\ho st
    etc

    3) Opened C:\portaudio\windows\pa_stable_v19_20071207\portau dio\build\msvc\portaudio.sln from Visual Studio. Selected Build Solution and I get these errors;

    Error 1 fatal error C1083: Cannot open include file: 'dsound.h': No such file or directory c:\portaudio\windows\pa_stable_v19_20071207\portau dio\src\hostapi\dsound\pa_win_ds.c 82
    Error 2 fatal error C1083: Cannot open include file: 'dsound.h': No such file or directory c:\portaudio\windows\pa_stable_v19_20071207\portau dio\src\hostapi\dsound\pa_win_ds_dynlink.h 62
    Warning 3 warning C4305: 'initializing' : truncation from 'double' to 'const float' c:\portaudio\windows\pa_stable_v19_20071207\portau dio\src\os\win\pa_x86_plain_converters.c 128

    I also tried just doing a Build portaudio but I get the same errors.

    Searching for dsound.h, I can not find it under \portaudio\src.

    Any suggestions or comments about what you did differently to get a successful compile? Perhaps I should try to get my hands on a trial or basic version of a newer Visual Studio though I'm not sure how that is related to this error? Thanks in advance for helping out.

    Brian

  9. #9
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    Haha, you need dsound.h and the ASIO sdk. dsound.h is a DirectSound header. I believe it also asks for dsound.lib later on. If you can't get it to compile, I would be more than happy to send it to you.

  10. #10
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    dsound.h is direct sound headerfile

    you need the http://msdn.microsoft.com/en-us/library/dd391528.aspx
    direct X SDK
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  11. #11
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Quote Originally Posted by vart View Post
    dsound.h is direct sound headerfile

    you need the http://msdn.microsoft.com/en-us/library/dd391528.aspx
    direct X SDK
    Thanks I realized this eventually, it resolved the dsound.h issues. However I am now getting something similar with WASAPI. From what I'm reading this API is only designed to work with Windows Vista, and I am using XP. Here is the complile error;

    Error 1 fatal error C1083: Cannot open include file: 'mmdeviceapi.h': No such file or directory c:\apple\portaudio\windows\pa_stable_v19_20071207\ portaudio\src\hostapi\wasapi\pa_win_wasapi.cpp 50

    Does it make sense to install this API also? If so do is there a link to do so? If not how can I get around this compile issue?

    At a higher level, now that I am installing all these API's beyond portaudio, does anyone have an opinion around which one would make the most sense for what I want to do in the end? I need to interact with my sound card using an ANSI C program such that I can capture the sound cards output and then manipulate the capture and send it back to the sound cards input for playback. Since I'm on a windows platform would DirectSound be the easiest for a device driver API beginner to figure out?

  12. #12
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  13. #13
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Quote Originally Posted by carrotcake1029 View Post
    Haha, you need dsound.h and the ASIO sdk. dsound.h is a DirectSound header. I believe it also asks for dsound.lib later on. If you can't get it to compile, I would be more than happy to send it to you.
    I don't think the compiled output of the code I listed above will help me much as I need to make this program much more elaborate, so I need to be able to compile source code myself.

    I spoke to soon before when saying installing DirectX SDK(from dxsdk_feb2007.exe) resolved my dsound.h issue. For some reason installing it just changed the compilation order so I only got the WASAPI error first. After removing the WASAPI folder, the 'dsound.h': No such file or directory error returned. Since I should be able to just use ASIO or wmme I decided to also try removing the dsound folder. After setting up the ASIO folders(from asiosdk2.2) as indicated in the tutorial it sees the asio.h but I still get these compilation errors.


    Error 1 error C2061: syntax error : identifier 'ASIOBool' c:\documents and settings\my documents\visual studio 2005\projects\pa_stable_v19_20071207\portaudio\src \hostapi\asio\pa_asio.cpp 211
    Error 2 error C2143: syntax error : missing ';' before '*' c:\documents and settings\my documents\visual studio 2005\projects\pa_stable_v19_20071207\portaudio\src \hostapi\asio\pa_asio.cpp 212

    etc

    Would it be possible for you to provide the step by step instructions for how you got portaudio to successfully compile in Visual Studio? I'm assuming it was more than download pa_stable_v19_20071207.tar, extract it, open project -> \pa_stable_v19_20071207\portaudio\build\msvc\porta udio.sln and hit build? Thanks in advance.

    Brian

    [email protected]

  14. #14
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    1. Download PortAudio, untar it, and open up the solution file in the build/msvc folder.

    2. Download ASIOSDK2 and put it in \src\hostapi\asio of the portaudio directory.

    3. Add C:\Program Files\Microsoft DirectX SDK (November 2008)\Include to the include path

    4. Add C:\Program Files\Microsoft DirectX SDK (November 2008)\Lib\x86\dsound.lib to the linker input additional dependencies.

    5. Build Solution

    You get a couple warnings but nothing important. This was my experience with Visual Studio 2008. You may or may not get the same results depending on what you have installed on your system.

  15. #15
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Quote Originally Posted by carrotcake1029 View Post
    1. Download PortAudio, untar it, and open up the solution file in the build/msvc folder.

    2. Download ASIOSDK2 and put it in \src\hostapi\asio of the portaudio directory.

    3. Add C:\Program Files\Microsoft DirectX SDK (November 2008)\Include to the include path

    4. Add C:\Program Files\Microsoft DirectX SDK (November 2008)\Lib\x86\dsound.lib to the linker input additional dependencies.

    5. Build Solution

    You get a couple warnings but nothing important. This was my experience with Visual Studio 2008. You may or may not get the same results depending on what you have installed on your system.
    Thanks for your help, I finally got it to build. Unfortunately for anyone else reading this post, I'm not sure exactly what the magic fix was. Since my previous post I downloaded Windows SDK(actually I upgraded to SP3 first), ran the Windows SDK configuration tool, then starting with an untouched version of portaudio(v19), I followed the instructions in the quote(make sure to put your ASIO files under src\hostapi\asio\asiosdk). The solution built with no errors or warnings and I was able to add and run the code from the tutorial pa_testsaw.c.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  2. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 05:37 PM
  3. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 08:07 PM
  4. How can I access a struct (from a header file)?
    By loxslay in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2006, 01:25 PM
  5. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 01:58 AM