libcm is a C development framework with an emphasis on audio signal processing applications.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cmAudioPort.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //( { file_desc: "Cross platform audio device interface." kw:[audio rt] }
  2. //
  3. // This interface provides data declarations for platform dependent
  4. // audio I/O functions. The implementation for the functions are
  5. // in platform specific modules. See cmAudioPortOsx.c and cmAudioPortAlsa.c.
  6. //
  7. // ALSA Notes:
  8. // Assign capture device to line or mic input:
  9. // amixer -c 0 cset iface=MIXER,name='Input Source',index=0 Mic
  10. // amixer -c 0 cset iface=MIXER,name='Input Source',index=0 Line
  11. //
  12. // -c 0 select the first card
  13. // -iface=MIXER the cset is targetting the MIXER component
  14. // -name='Input Source',index=0 the control to set is the first 'Input Source'
  15. // Note that the 'Capture' control sets the input gain.
  16. //
  17. // See alsamixer for a GUI to accomplish the same thing.
  18. //
  19. //
  20. //)
  21. #ifndef cmAudioPort_h
  22. #define cmAudioPort_h
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. //(
  27. typedef unsigned cmApRC_t; // Audio port interface result code.
  28. typedef float cmApSample_t; // Audio sample type.
  29. enum
  30. {
  31. kOkApRC =0,
  32. kSysErrApRC,
  33. kInvalidDevIdApRC,
  34. kAudioPortFileFailApRC,
  35. kParamRangeErrorApRC,
  36. kThreadFailApRC
  37. };
  38. // cmApAudioPacket_t flags
  39. enum
  40. {
  41. kInterleavedApFl = 0x01, // The audio samples are interleaved.
  42. kFloatApFl = 0x02 // The audio samples are single precision floating point values.
  43. };
  44. // Audio packet record used by the cmApAudioPacket_t callback.
  45. // Audio ports send and receive audio using this data structure.
  46. typedef struct
  47. {
  48. unsigned devIdx; // device associated with packet
  49. unsigned begChIdx; // first device channel
  50. unsigned chCnt; // count of channels
  51. unsigned audioFramesCnt; // samples per channel (see note below)
  52. unsigned bitsPerSample; // bits per sample word
  53. unsigned flags; // kInterleavedApFl | kFloatApFl
  54. void* audioBytesPtr; // pointer to sample data
  55. void* userCbPtr; // user defined value passed in cmApDeviceSetup()
  56. cmTimeSpec_t timeStamp; // Packet time stamp.
  57. } cmApAudioPacket_t;
  58. // Audio port callback signature.
  59. // inPktArray[inPktCnt] are full packets of audio coming from the ADC to the application.
  60. // outPktArray[outPktCnt] are empty packets of audio which will be filled by the application
  61. // and then sent to the DAC.
  62. //
  63. // The value of audioFrameCnt gives the number of samples per channel which are available
  64. // in the packet data buffer 'audioBytesPtr'. The callback function may decrease this number in
  65. // output packets if the number of samples available is less than the size of the buffer.
  66. // It is the responsibility of the calling audio port to notice this change and pass the new,
  67. // decreased number of samples to the hardware.
  68. //
  69. // In general it should be assmed that this call is made from a system thread which is not
  70. // the same as the application thread.
  71. // The usual thread safety precautions should therefore be taken if this function implementation
  72. // interacts with data structures also handled by the application. The audio buffer class (\see cmApBuf.h)
  73. // is designed to provide a safe and efficient way to communicate between
  74. // the audio thread and the application.
  75. typedef void (*cmApCallbackPtr_t)( cmApAudioPacket_t* inPktArray, unsigned inPktCnt, cmApAudioPacket_t* outPktArray, unsigned outPktCnt );
  76. // Setup the audio port management object for this machine.
  77. cmApRC_t cmApInitialize( cmRpt_t* rpt );
  78. // Stop all audio devices and release any resources held
  79. // by the audio port management object.
  80. cmApRC_t cmApFinalize();
  81. // Return the count of audio devices attached to this machine.
  82. unsigned cmApDeviceCount();
  83. // Get a textual description of the device at index 'devIdx'.
  84. const char* cmApDeviceLabel( unsigned devIdx );
  85. // Given an audio device label return the associated device index.
  86. unsigned cmApDeviceLabelToIndex( const cmChar_t* label );
  87. // Get the count of audio input or output channesl on device at index 'devIdx'.
  88. unsigned cmApDeviceChannelCount( unsigned devIdx, bool inputFl );
  89. // Get the current sample rate of a device. Note that if the device has both
  90. // input and output capability then the sample rate is the same for both.
  91. double cmApDeviceSampleRate( unsigned devIdx );
  92. // Get the count of samples per callback for the input or output for this device.
  93. unsigned cmApDeviceFramesPerCycle( unsigned devIdx, bool inputFl );
  94. // Configure a device.
  95. // All devices must be setup before they are started.
  96. // framesPerCycle is the requested number of samples per audio callback. The
  97. // actual number of samples made from a callback may be smaller. See the note
  98. // regarding this in cmApAudioPacket_t.
  99. // If the device cannot support the requested configuration then the function
  100. // will return an error code.
  101. // If the device is started when this function is called then it will be
  102. // automatically stopped and then restarted following the reconfiguration.
  103. // If the reconfiguration fails then the device may not be restared.
  104. cmApRC_t cmApDeviceSetup(
  105. unsigned devIdx,
  106. double srate,
  107. unsigned framesPerCycle,
  108. cmApCallbackPtr_t callbackPtr,
  109. void* userCbPtr );
  110. // Start a device. Note that the callback may be made prior to this function returning.
  111. cmApRC_t cmApDeviceStart( unsigned devIdx );
  112. // Stop a device.
  113. cmApRC_t cmApDeviceStop( unsigned devIdx );
  114. // Return true if the device is currently started.
  115. bool cmApDeviceIsStarted( unsigned devIdx );
  116. // Print a report of all the current audio device configurations.
  117. void cmApReport( cmRpt_t* rpt );
  118. // Test the audio port by synthesizing a sine signal or passing audio through
  119. // from the input to the output. This is also a good example of how to
  120. // use all of the functions in the interface.
  121. // Set runFl to false to print a report without starting any audio devices.
  122. // See cmAudiotPortTest.c for usage example for this function.
  123. int cmApPortTest(bool runFl, cmRpt_t* rpt, int argc, const char* argv[] );
  124. //)
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif