Пример #1
0
void SND_StopSoundTrack(void)
{
	int cmdResult;
	cmdResult = mciSendStringA("stop myFile", NULL, 0, 0);
	if (cmdResult)
		SND_LogMCI_Error("stop myFile",cmdResult);

	cmdResult = mciSendStringA("close myFile", NULL, 0, 0);
	if (cmdResult)
		SND_LogMCI_Error("close myFile",cmdResult);
}
Пример #2
0
static void Audio_waitToStop(Audio *audio, const char *alias, bool *m_playing)
{
   do {
      /* check user's stop */
      if(*m_playing == false) {
         sprintf(audio->buf, "stop _%s wait", alias);
         mciSendStringA(audio->buf, NULL, 0, NULL);
         break;
      }
      MMDAgent_sleep(AUDIOTHREAD_ENDSLEEPMS);
      /* check end of sound */
      sprintf(audio->buf, "status _%s mode wait", alias);
      mciSendStringA(audio->buf, audio->ret, sizeof(audio->ret), NULL);
   } while(MMDAgent_strequal(audio->ret, "playing") == true);
}
Пример #3
0
static void test_midi_mci(HWND hwnd)
{
    MCIERROR err;
    char buf[1024];
    memset(buf, 0, sizeof(buf));

    err = mciSendStringA("sysinfo sequencer quantity", buf, sizeof(buf), hwnd);
    ok(!err, "mci sysinfo sequencer quantity returned %d\n", err);
    if (!err) trace("Found %s MCI sequencer devices\n", buf);

    if (!strcmp(buf, "0")) return;

    err = mciSendStringA("capability sequencer can record", buf, sizeof(buf), hwnd);
    ok(!err, "mci sysinfo sequencer quantity returned %d\n", err);
    if(!err) ok(!strcmp(buf, "false"), "capability can record is %s\n", buf);
}
Пример #4
0
const char *MusicDriver_Win32::Start(const char * const *parm)
{
	MIDIOUTCAPS midicaps;
	UINT nbdev;
	UINT_PTR dev;
	char buf[16];

	mciSendStringA("capability sequencer has audio", buf, lengthof(buf), 0);
	if (strcmp(buf, "true") != 0) return "MCI sequencer can't play audio";

	memset(&_midi, 0, sizeof(_midi));
	_midi.new_vol = -1;

	/* Get midi device */
	_midi.devid = MIDI_MAPPER;
	for (dev = 0, nbdev = midiOutGetNumDevs(); dev < nbdev; dev++) {
		if (midiOutGetDevCaps(dev, &midicaps, sizeof(midicaps)) == 0 && (midicaps.dwSupport & MIDICAPS_VOLUME)) {
			_midi.devid = dev;
			break;
		}
	}

	if (NULL == (_midi.wait_obj = CreateEvent(NULL, FALSE, FALSE, NULL))) return "Failed to create event";

	/* The lpThreadId parameter of CreateThread (the last parameter)
	 * may NOT be NULL on Windows 95, 98 and ME. */
	DWORD threadId;
	if (NULL == (_midi.thread = CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId))) return "Failed to create thread";

	return NULL;
}
Пример #5
0
void SND_StartSoundTrack(void)
{
	int cmdResult;
	cmdResult = mciSendStringA("play myFile", NULL, 0, 0);

	if (cmdResult)
		SND_LogMCI_Error("play myFile",cmdResult);
}
Пример #6
0
//This function cannot play same file simutaneously, but not for different file.
void SystemClass::PlaySoundFile(std::string fileName)
{
	std::string playCmd = "play mp3" + fileName +" from 0";
	auto msg = mciSendStringA(playCmd.c_str(), NULL, 0, 0);
	WCHAR tmp[128];
	mciGetErrorString(msg, tmp, 128);

}
Пример #7
0
void SystemClass::PreLoadSoundFile(std::string fileName)
{
	std::string openCmd = "open " + fileName + " type mpegvideo alias mp3"+fileName;
	WCHAR tmp[128];

	auto msg = mciSendStringA(openCmd.c_str(), NULL, 128, 0);
	mciGetErrorString(msg, tmp, 128);

}
Пример #8
0
DWORD WINAPI TextPlayer::Play(LPVOID arg)
{
    TextPlayer* textPlayer = (TextPlayer*)arg;
    try
    {
        ExceptionHelper::SetupStructuredExceptionsTranslation();

        wstring text = wstring(textPlayer->currentTextToPlay);

        textPlayer->logger->Log(LogLevels::Trace, L"Start playing sentence '" + text + L"'.");

        wstring responseQuery = L"https://translate.google.com/translate_tts?tl=en&client=t&q=" + textPlayer->requestProvider->EscapeText(text)
            + L"&tk=" + textPlayer->translationService->GetHash(text);

        vector<unsigned char> audio = textPlayer->requestProvider->GetResponse(responseQuery);

        string filePath = textPlayer->SaveToFile(audio);

        audio.clear();

        string openFileCommand = "open " + filePath + " type mpegvideo alias " + string(AUDIO_FILE_NAME);
        mciSendStringA(openFileCommand.c_str(), nullptr, 0, nullptr);

        string playAudioCommand = "play " + string(AUDIO_FILE_NAME) + " wait";
        mciSendStringA(playAudioCommand.c_str(), nullptr, 0, nullptr);

        string closeAudioCommand = "close " + string(AUDIO_FILE_NAME);
        mciSendStringA(closeAudioCommand.c_str(), nullptr, 0, nullptr);

        textPlayer->logger->Log(LogLevels::Trace, L"End playing sentence.");

        return 0;
    }
    catch (const SelectedTextTranslateBaseException& error)
    {
        ExceptionHelper::HandleNonFatalException(textPlayer->logger, textPlayer->errorHandler, L"Error playing sentence.", error);
    }
    catch(...)
    {
        ExceptionHelper::HandleNonFatalException(textPlayer->logger, textPlayer->errorHandler, L"Error playing sentence.");
    }

    return -1;
}
Пример #9
0
const char* CSound::GetStatus()
{
	static const size_t nBufferSize = 100;
	static char szBuffer[ nBufferSize ] = {};

	StrUtils::FormatString( m_sDeviceCommand, "status %s mode wait", m_sDeviceAlias.c_str() );
	/*int nResult = */mciSendStringA( m_sDeviceCommand.c_str(), szBuffer, nBufferSize, 0);

	return szBuffer;
}
Пример #10
0
bool CSound::PlaySound( const string& sSoundFile, bool bWait /*= false*/ )
{
	bool bResult = false;
	if( !sSoundFile.empty() )
	{
		string sPlayCommand = string( "play " ) + sSoundFile + ( bWait ? " wait" : "" );
		bResult = ( 0 == mciSendStringA( sPlayCommand.c_str(), NULL, 0, 0 ) );
	}
	return bResult;
}
Пример #11
0
void playSound(int sid,int repeat)
{
	char cmdStr[32];
	stopSound(sid);
	if(repeat)
		sprintf(cmdStr,"play S%d from 0 repeat",sid);
	else
		sprintf(cmdStr,"play S%d from 0",sid);
	mciSendStringA(cmdStr,NULL,0,NULL);
}
Пример #12
0
void loadSound(const char *fileName,ACL_Sound *pSound)
{
	char *cmdStr;
	int len = strlen(fileName)*sizeof(char);
	len +=64;
	cmdStr = (char*)malloc(len);
	sprintf(cmdStr,"open \"%s\" type mpegvideo alias S%d",fileName,g_soundID);
	*pSound = g_soundID;
	++g_soundID;
	mciSendStringA(cmdStr,NULL,0,NULL);
	free(cmdStr);
}
Пример #13
0
bool CSound::SetVolume( size_t nVolume  ) // region between 0 and 1000
{
	ASSERT(IN_RANGE(nVolume, 0, 1000));
	StrUtils::FormatString( m_sDeviceCommand, "setaudio %s volume to %u", m_sDeviceAlias.c_str(), nVolume );
	
	bool result = (0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0));

	if (result)
	{
		on_volume_chnaged(nVolume);
	}
	
	return result;
}
Пример #14
0
size_t CSound::GetLength()
{
	size_t nResult = -1;

	static const char nBufferLen = 16;
	static char szBuffer[ nBufferLen ] = {};

	StrUtils::FormatString( m_sDeviceCommand, "status %s length", m_sDeviceAlias.c_str() );
	if( 0 == mciSendStringA( m_sDeviceCommand.c_str(), szBuffer, nBufferLen, 0) ) {
		nResult = atol( szBuffer );
	}
	
	return nResult;
}
Пример #15
0
bool CSound::Play( const string& sSoundFile, bool bWait /*= false*/ )
{
	START_FUNCTION_BOOL();

	if( !m_sDeviceAlias.empty() && !m_sSoundFile.empty() ) {
		StrUtils::FormatString( m_sDeviceCommand, "close %s", m_sDeviceAlias.c_str() );
		mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0 );
	}

	m_sSoundFile = sSoundFile;

	StrUtils::FormatString( m_sDeviceCommand, "open \"%s\" alias %s", m_sSoundFile.c_str(), m_sDeviceAlias.c_str() );
	m_bOpen = ( 0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) );
	if( !m_bOpen ) break;

	SetVolume( m_nVolumeLevel );

	m_bIsPlaying = true;
	StrUtils::FormatString( m_sDeviceCommand, "play %s %s", m_sDeviceAlias.c_str(), (bWait ? "wait" : "") );
	if( 0 != mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) ) break;

	END_FUNCTION_BOOL();
}
Пример #16
0
void SND_InitSoundTrack(char* filename)
{
	char command[256];
	int cmdResult;

	Log_Printf("[SND_InitSoundTrack] start '%s'.\n",filename);

	sprintf(command,format,filename);

	Log_Printf(command);
	Log_Printf("\n");

	cmdResult = mciSendStringA(command, NULL, 0, 0);

	if (cmdResult)
		SND_LogMCI_Error(command,cmdResult);
}
Пример #17
0
/**
 * Execute an MCI command string.
 *
 * @return              @c true, if successful.
 */
static int sendMCICmd(char* returnInfo, int returnLength,
                      const char *format, ...)
{
    char                buf[300];
    va_list             args;
    MCIERROR            error;

    va_start(args, format);
    dd_vsnprintf(buf, sizeof(buf), format, args);
    va_end(args);

    if((error = mciSendStringA(buf, returnInfo, returnLength, NULL)))
    {
        mciGetErrorStringA(error, buf, 300);
        Con_Message("DM_WinCD: %s", buf);

        return false;
    }

    return true;
}
Пример #18
0
static bool Audio_openAndStart(Audio *audio, const char *alias, char *file)
{
   bool first = true;

   /* wait */
   sprintf(audio->buf, "open \"%s\" alias _%s wait", file, alias);
   if (mciSendStringA(audio->buf, NULL, 0, 0) != 0) {
      return false;
   }

   /* enqueue */
   sprintf(audio->buf, "cue _%s output wait", alias);
   if (mciSendStringA(audio->buf, NULL, 0, 0) != 0) {
      sprintf(audio->buf, "close _%s wait", alias);
      mciSendStringA(audio->buf, NULL, 0, 0);
      return false;
   }

   /* start */
   sprintf(audio->buf, "play _%s", alias);
   if (mciSendStringA(audio->buf, NULL, 0, 0) != 0) {
      sprintf(audio->buf, "close _%s wait", alias);
      mciSendStringA(audio->buf, NULL, 0, 0);
      return false;
   }

   /* wait till sound starts */
   do {
      if(first == true)
         first = false;
      else
         MMDAgent_sleep(AUDIOTHREAD_STARTSLEEPMS);
      /* check sound start */
      sprintf(audio->buf, "status _%s mode wait", alias);
      mciSendStringA(audio->buf, audio->ret, sizeof(audio->ret), NULL);
   } while(MMDAgent_strequal(audio->ret, "playing") == false);

   return true;
}
Пример #19
0
bool CSound::RightOff()
{
	StrUtils::FormatString( m_sDeviceCommand, "setaudio %s right off", m_sDeviceAlias.c_str() );
	return ( 0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) );
}
Пример #20
0
bool CSound::SetRightVolume( size_t nVolume )
{
	StrUtils::FormatString( m_sDeviceCommand, "setaudio %s right volume to %u", m_sDeviceAlias.c_str(), nVolume );
	return ( 0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) );
}
Пример #21
0
static int
do_play_sound (const char *psz_file, unsigned long ui_volume)
{
  int i_result = 0;
  MCIERROR mci_error = 0;
  char sz_cmd_buf_a[520];
  char sz_ret_buf_a[520];
  MMRESULT mm_result = MMSYSERR_NOERROR;
  unsigned long ui_volume_org = 0;
  BOOL b_reset_volume = FALSE;
  char warn_text[560];

  /* Since UNICOWS.DLL includes only a stub for mciSendStringW, we
     need to encode the file in the ANSI codepage on Windows 9X even
     if w32_unicode_filenames is non-zero.  */
  if (w32_major_version <= 4 || !w32_unicode_filenames)
    {
      char fname_a[MAX_PATH], shortname[MAX_PATH], *fname_to_use;

      filename_to_ansi (psz_file, fname_a);
      fname_to_use = fname_a;
      /* If the file name is not encodable in ANSI, try its short 8+3
	 alias.  This will only work if w32_unicode_filenames is
	 non-zero.  */
      if (_mbspbrk ((const unsigned char *)fname_a,
		    (const unsigned char *)"?"))
	{
	  if (w32_get_short_filename (psz_file, shortname, MAX_PATH))
	    fname_to_use = shortname;
	  else
	    mci_error = MCIERR_FILE_NOT_FOUND;
	}

      if (!mci_error)
	{
	  memset (sz_cmd_buf_a, 0, sizeof (sz_cmd_buf_a));
	  memset (sz_ret_buf_a, 0, sizeof (sz_ret_buf_a));
	  sprintf (sz_cmd_buf_a,
		   "open \"%s\" alias GNUEmacs_PlaySound_Device wait",
		   fname_to_use);
	  mci_error = mciSendStringA (sz_cmd_buf_a,
				      sz_ret_buf_a, sizeof (sz_ret_buf_a), NULL);
	}
    }
  else
    {
      wchar_t sz_cmd_buf_w[520];
      wchar_t sz_ret_buf_w[520];
      wchar_t fname_w[MAX_PATH];

      filename_to_utf16 (psz_file, fname_w);
      memset (sz_cmd_buf_w, 0, sizeof (sz_cmd_buf_w));
      memset (sz_ret_buf_w, 0, sizeof (sz_ret_buf_w));
      /* _swprintf is not available on Windows 9X, so we construct the
	 UTF-16 command string by hand.  */
      wcscpy (sz_cmd_buf_w, L"open \"");
      wcscat (sz_cmd_buf_w, fname_w);
      wcscat (sz_cmd_buf_w, L"\" alias GNUEmacs_PlaySound_Device wait");
      mci_error = mciSendStringW (sz_cmd_buf_w,
				  sz_ret_buf_w, ARRAYELTS (sz_ret_buf_w) , NULL);
    }
  if (mci_error != 0)
    {
      strcpy (warn_text,
	      "mciSendString: 'open' command failed to open sound file ");
      strcat (warn_text, psz_file);
      SOUND_WARNING (mciGetErrorString, mci_error, warn_text);
      i_result = (int) mci_error;
      return i_result;
    }
  if ((ui_volume > 0) && (ui_volume != UINT_MAX))
    {
      mm_result = waveOutGetVolume ((HWAVEOUT) WAVE_MAPPER, &ui_volume_org);
      if (mm_result == MMSYSERR_NOERROR)
        {
          b_reset_volume = TRUE;
          mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume);
          if (mm_result != MMSYSERR_NOERROR)
            {
	      SOUND_WARNING (waveOutGetErrorText, mm_result,
			     "waveOutSetVolume: failed to set the volume level"
			     " of the WAVE_MAPPER device.\n"
			     "As a result, the user selected volume level will"
			     " not be used.");
            }
        }
      else
        {
          SOUND_WARNING (waveOutGetErrorText, mm_result,
			 "waveOutGetVolume: failed to obtain the original"
                         " volume level of the WAVE_MAPPER device.\n"
                         "As a result, the user selected volume level will"
                         " not be used.");
        }
    }
  memset (sz_cmd_buf_a, 0, sizeof (sz_cmd_buf_a));
  memset (sz_ret_buf_a, 0, sizeof (sz_ret_buf_a));
  strcpy (sz_cmd_buf_a, "play GNUEmacs_PlaySound_Device wait");
  mci_error = mciSendStringA (sz_cmd_buf_a, sz_ret_buf_a, sizeof (sz_ret_buf_a),
			      NULL);
  if (mci_error != 0)
    {
      strcpy (warn_text,
	      "mciSendString: 'play' command failed to play sound file ");
      strcat (warn_text, psz_file);
      SOUND_WARNING (mciGetErrorString, mci_error, warn_text);
      i_result = (int) mci_error;
    }
  memset (sz_cmd_buf_a, 0, sizeof (sz_cmd_buf_a));
  memset (sz_ret_buf_a, 0, sizeof (sz_ret_buf_a));
  strcpy (sz_cmd_buf_a, "close GNUEmacs_PlaySound_Device wait");
  mci_error = mciSendStringA (sz_cmd_buf_a, sz_ret_buf_a, sizeof (sz_ret_buf_a),
			      NULL);
  if (b_reset_volume == TRUE)
    {
      mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume_org);
      if (mm_result != MMSYSERR_NOERROR)
        {
          SOUND_WARNING (waveOutGetErrorText, mm_result,
			 "waveOutSetVolume: failed to reset the original"
                         " volume level of the WAVE_MAPPER device.");
        }
    }
  return i_result;
}
Пример #22
0
static bool MidiIntIsSongPlaying()
{
	char buf[16];
	mciSendStringA("status song mode", buf, sizeof(buf), 0);
	return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
}
Пример #23
0
bool CSound::Close()
{
	StrUtils::FormatString( m_sDeviceCommand, "close %s", m_sDeviceAlias.c_str() );
	m_bOpen = m_bIsPlaying = false;
	return ( 0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) );
}
Пример #24
0
static void Audio_close(Audio *audio, const char *alias)
{
   sprintf(audio->buf, "close _%s wait", alias);
   mciSendStringA(audio->buf, NULL, 0, NULL);
}
Пример #25
0
bool CSound::Resume()
{
	m_bPause = false;
	StrUtils::FormatString( m_sDeviceCommand, "resume %s", m_sDeviceAlias.c_str() );
	return ( 0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) );
}
Пример #26
0
void stopSound(int sid)
{
	char cmdStr[32];
	sprintf(cmdStr,"stop S%d",sid);
	mciSendStringA(cmdStr,NULL,0,NULL);
}
Пример #27
0
bool CSound::LeftOn()
{
	StrUtils::FormatString( m_sDeviceCommand, "setaudio %s left on", m_sDeviceAlias.c_str() );
	return ( 0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) );
}
Пример #28
0
void SystemClass::CloseSoundFile(std::string fileName) {
	std::string closeCmd = "close " + fileName;
	mciSendStringA(closeCmd.c_str(), NULL, 0, 0);
}
Пример #29
0
/**************************************************************************
 * 				mciSendString			[MMSYSTEM.702]
 */
DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
			     UINT16 uRetLen, HWND16 hwndCallback)
{
    return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback));
}
Пример #30
0
bool CSound::Pause()
{
	StrUtils::FormatString( m_sDeviceCommand, "pause %s", m_sDeviceAlias.c_str() );
	return m_bPause = ( 0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0) );
}