0

The sound output functions are giving me unexpected messages. Is this a sign I'm doing something wrong? If so what? Otherwise is there a good source that explains what these messages might be?

waveOutOpen() gives me message 955 MM_WOM_OPEN as documented, followed by an undocumented 1024 (possibly DDM_SETFMT, DM_GETDEFID, NIN_SELECT, TBM_GETPOS, WM_PSD_PAGESETUPDLG, WM_USER, according to https://wiki.winehq.org/List_Of_Windows_Messages).

In main thread:

  hAudioOut = CreateThread( 0, 0, AudioOutThreadProc, this, 0, &dwAudioOutId );

      if( !hAudioOut ) {
          AKS( AKSWarn, "Audio Out CreateThread() fail" );
          return;
      }

In the resulting audio thread:

static DWORD WINAPI AudioOutThreadProc( LPVOID lpParameter ) {

  Interpreter* pinterp = (Interpreter *) lpParameter;
  WAVEFORMATEX waveFormat;

  waveFormat.cbSize          = sizeof(waveFormat);
  waveFormat.wFormatTag      = WAVE_FORMAT_PCM;
  waveFormat.nChannels       = 1;
  waveFormat.nSamplesPerSec  = (int) dFreqEval;
  waveFormat.wBitsPerSample  = iOutputBits;
  waveFormat.nBlockAlign     = waveFormat.nChannels *
                               waveFormat.wBitsPerSample / 8;
  waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec *
                               waveFormat.nBlockAlign;

  MMRESULT openRes = waveOutOpen( &waveOut, WAVE_MAPPER, &waveFormat,
                                  (DWORD_PTR) dwAudioOutId, (DWORD_PTR) this,
                                  CALLBACK_THREAD /*| WAVE_FORMAT_DIRECT*/ );

  if ( openRes != MMSYSERR_NOERROR )
      Log( "waveOutOpen() = %d", openRes );

  MSG msg;
  int iRV;
  while ( iRV = GetMessage( &msg, 0, 0, 0 ) ) {

      Log( "got  message %d", msg.message );

      // Is the main thread asking us to stop?
      if ( pinterp->bStop ) {

          Log( "AudioInThreadProc(): bStop" );
          return EXIT_SUCCESS;
      }

      // Did we get an error?
      if ( iRV == -1 ) {
          Log( "GetMessage() = -1: %d", GetLastError() );
          abort();
      }

      // Did we get an expected message?  (Only one expected,
      // which tells us its time to write more data.)
      if ( msg.message == WOM_DONE )
          pinterp->Write();

      // Anything else--log it.
      else
          Log( "got unknown message %d", msg.message );
  }

  Log( "AudioInThreadProc(): GetMessage = return" );

  return msg.wParam;
}

waveOutWrite() isn't documented to give any messages, but is giving me message 1024 as well.

Swiss Frank
  • 1,985
  • 15
  • 33
  • 1
    Your code snippets don't have/show `waveOutWrite` call. 1024 is `WM_USER`, which can be posted by something else as well. – Roman R. Mar 23 '16 at 18:18
  • The 1024 (lets call them WM_USER though the intended token could be something else; I cited several other possibilities above) messages are coming at the exact frequency of the waveOut calls, and immediately in time with them completing. I didn't include the `waveOutWrite()` because a complete snippet would be huge, and I imagine that the answer should either be apparent in the `waveOutOpen()` call or known from experience. – Swiss Frank Mar 24 '16 at 03:22
  • 1
    The message "could be something else" because that is specifically what `WM_USER` is intended for: it is the first in a range of window messages reserved for window classes to use for whatever they see fit (this range goes up to, but not including, `WM_APP`). The messages you send to standard controls like `LVM_INSERTITEM` and `TBM_GETPOS` are in this `WM_USER` range. I'm not sure what window the message in your case is being sent to, though I assume it's internal to the multimedia system? – andlabs Mar 24 '16 at 23:54
  • Its not merely in the WM_USER range, its WM_USER itself. I'm not sending it; the waveOut library is sending it to ME. And its not going to a window, its going to a thread launched with the `CreateThread()` call shown above.. Inside `AudioOutThreadProc` is the usual `GetMessage( &msg, 0, 0, 0 )` loop, and that's getting the WM_USER. – Swiss Frank Mar 25 '16 at 16:18
  • `WM_USER` is the first message in the `WM_USER` range; its exact value is meaningless. It doesn't matter who is sending the message to whm. You need to look at the other fields of the `MSG` structure to see whether the message is really going to a window or not. The second parameter to `GetMessage()` in your case is `NULL`, which does not filter by window. – andlabs Mar 25 '16 at 20:58
  • Given that the messages are EXACTLY coordinated with the waveOpen messages, I'd guess its coming from waveOpen's internals. And I don't understand your mention of window? This is a THREAD I created as shown in the first code snapshot in my original question above. Its not getting any messages whatsoever, despite being in an app with lots of windows and getting lots of user activity and so on, EXCEPT 1) the waveOut documented messages, 2) these ghost WM_USER messages. I'll look at the entire msg structure though (thx for the idea!) and see if it holds any clues. – Swiss Frank Mar 27 '16 at 11:57
  • Error 1024 (0x400) is defined in `mmsystem.h` as `MIXERR_INVALLINE`. – Ken White Apr 01 '16 at 17:21
  • Thanks Ken, but do you know why it'd be coming to me as a thread message, instead of say as an error code? Google and my VS2008 docs don't show much for this except as a return code for mixerGetLineInfo(), function I'm not using. (I'm not using any function starting mixer.) – Swiss Frank Apr 02 '16 at 05:52

0 Answers0