[xiph-cvs] cvs commit: ao/src/plugins/mmsound mmsound.c mmsound.def mmsound.dsp

Chris Wolf cwolf at xiph.org
Fri Sep 7 13:41:40 PDT 2001



cwolf       01/09/07 13:41:40

  Added:       src/plugins/mmsound mmsound.c mmsound.def mmsound.dsp
  Log:
  Add win32 Multi Media plugin, contributed by Matthew Brown

Revision  Changes    Path
1.1                  ao/src/plugins/mmsound/mmsound.c

Index: mmsound.c
===================================================================
/*
 *
 *  mmsound.c
 *
 *      Copyright (C) Matthew Brown - Sept. July 2001
 *
 *  This file is part of libao, a cross-platform library.  See
 *  README for a history of this source code.
 *
 *  libao is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  libao is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <windows.h>
#include <stdio.h>
#include <mmsystem.h>
#include <ao/ao.h>
#include <ao/plugin.h>

HANDLE notdone;

tatic	void CALLBACK waveOutProc(HWAVEOUT hwo,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2)
{
        if (uMsg == WOM_DONE)
        {
                ReleaseSemaphore(notdone, 1, NULL);
        }
}

typedef struct ao_mmsound_internal {
        HWAVEOUT m_hWaveOut;
        WAVEHDR	m_waveHeader[2];
        uint_32 buf_size;
        void *buffer[2];
        int currentb;
} ao_mmsound_internal;

tatic char *ao_mmsound_options[] = {"buf_size"};

tatic ao_info ao_mmsound_info =
{
        AO_TYPE_LIVE,
        "Win9x waveout audio output ",
        "mmsound",
        "Matthew Brown <matt at digitalblues.org>",
        "WARNING: This driver is untested!",
        AO_FMT_NATIVE,
        20,
        ao_mmsound_options,
        1
};

int ao_plugin_test()
{
        return 1; /* This plugin works in default mode */
}

ao_info *ao_plugin_driver_info(void)
{
        return &ao_mmsound_info;
}

int ao_plugin_device_init(ao_device *device)
{
        ao_mmsound_internal *internal;

        internal = (ao_mmsound_internal *) malloc(sizeof(ao_mmsound_internal));

        if (internal == NULL)	
                return 0; /* Could not initialize device memory */

        device->internal = internal;

        internal->buf_size = 0;

        return 1; /* Memory alloc successful */
}

int ao_plugin_set_option(ao_device *device, const char *key, const char *value)
{
        ao_mmsound_internal *internal = (ao_mmsound_internal *) device->internal;
        if (!strcmp(key, "buf_size"))
                internal->buf_size = atoi(value);
        
        return 1;
}

/*
 * open the audio device for writing to
 */
int ao_plugin_open(ao_device *device, ao_sample_format *format)
{
        ao_mmsound_internal *internal = (ao_mmsound_internal *) device->internal;
        
        MMRESULT errCode;
        WAVEFORMATEX wfx;

        wfx.wFormatTag = 1;	// WAVE_FORMAT_PCM
        wfx.nChannels = format->channels;
        wfx.nSamplesPerSec = format->rate;
        wfx.nAvgBytesPerSec = ((format->rate)*((format->channels*format->bits)/8));
        wfx.nBlockAlign = ((format->channels*format->bits)/8);
        wfx.wBitsPerSample = format->bits;
        wfx.cbSize = 0;

        errCode = waveOutOpen(	&internal->m_hWaveOut,
                                                        WAVE_MAPPER,
                                                        &wfx,
                                                        (DWORD)waveOutProc,
                                                        0,
                                                        (DWORD)CALLBACK_FUNCTION);

        if (errCode != MMSYSERR_NOERROR) return 0;

        if(internal->buf_size == 0)
        {
                internal->buf_size = 352800;
        }

        memset(&internal->m_waveHeader[0],0,sizeof(WAVEHDR));
        memset(&internal->m_waveHeader[1],0,sizeof(WAVEHDR));
        internal->buffer[0] = malloc(internal->buf_size);
        internal->buffer[1] = malloc(internal->buf_size);
        internal->currentb = 0;

        notdone = CreateSemaphore(NULL, 0, 1, NULL);
        ReleaseSemaphore(notdone, 1, NULL);

        device->driver_byte_format = AO_FMT_NATIVE;
        
        return 1;
}

/*
 * play the sample to the already opened file descriptor
 */
int ao_plugin_play(ao_device *device, const char *output_samples, 
                uint_32 num_bytes)
{
        ao_mmsound_internal *internal = (ao_mmsound_internal *) device->internal;
        
        if(num_bytes > internal->buf_size)
                return 0;

        if (internal->m_waveHeader[internal->currentb].dwFlags&WHDR_PREPARED)
                waveOutUnprepareHeader(internal->m_hWaveOut,&internal->m_waveHeader[internal->currentb],sizeof(WAVEHDR));
        
        // Prepare internal->buffer[n] to be inteserted int WaveOut buffer.
        memcpy(internal->buffer[internal->currentb], output_samples, num_bytes);

        internal->m_waveHeader[internal->currentb].lpData = (char*)internal->buffer[internal->currentb];
        internal->m_waveHeader[internal->currentb].dwBufferLength = (unsigned long)num_bytes;
        waveOutPrepareHeader(internal->m_hWaveOut,&internal->m_waveHeader[internal->currentb],sizeof(WAVEHDR));

        // Send internal->buffer[n] to the WaveOut device buffer.
        waveOutWrite(internal->m_hWaveOut,&internal->m_waveHeader[internal->currentb],sizeof(WAVEHDR));
        WaitForSingleObject(notdone, INFINITE);

        internal->currentb++;
        if(internal->currentb >= 2) internal->currentb = 0;

        return 1;
}

int ao_plugin_close(ao_device *device)
{
        ao_mmsound_internal *internal = (ao_mmsound_internal *) device->internal;

        CloseHandle(notdone);
        free(internal->buffer[0]);
        free(internal->buffer[1]);
        
        waveOutReset(internal->m_hWaveOut);
        waveOutClose(internal->m_hWaveOut);

        return 1;
}

void ao_plugin_device_clear(ao_device *device)
{
        ao_mmsound_internal *internal = (ao_mmsound_internal *) device->internal;

        free(internal);
}

1.1                  ao/src/plugins/mmsound/mmsound.def

Index: mmsound.def
===================================================================
LIBRARY
; Don't explicitly name DLL here, let the linker do it.
;
DESCRIPTION "Entry points for mmsound.dll"
;
EXPORTS

ao_plugin_test
ao_plugin_driver_info
ao_plugin_device_init
ao_plugin_set_option
ao_plugin_open
ao_plugin_play
ao_plugin_close
ao_plugin_device_clear

1.1                  ao/src/plugins/mmsound/mmsound.dsp

Index: mmsound.dsp
===================================================================
# Microsoft Developer Studio Project File - Name="mmsound" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **

# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102

CFG=mmsound - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE 
!MESSAGE NMAKE /f "mmsound.mak".
!MESSAGE 
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE 
!MESSAGE NMAKE /f "mmsound.mak" CFG="mmsound - Win32 Debug"
!MESSAGE 
!MESSAGE Possible choices for configuration are:
!MESSAGE 
!MESSAGE "mmsound - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "mmsound - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE 

# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe

!IF  "$(CFG)" == "mmsound - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMSOUND_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /I "..\..\..\win32\include" /I "." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMSOUND_EXPORTS" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib winmm.lib /nologo /dll /machine:I386

!ELSEIF  "$(CFG)" == "mmsound - Win32 Debug"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMSOUND_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\include" /I "..\..\..\win32\include" /I "." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MMSOUND_EXPORTS" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib winmm.lib /nologo /dll /debug /machine:I386 /pdbtype:sept

!ENDIF 

# Begin Target

# Name "mmsound - Win32 Release"
# Name "mmsound - Win32 Debug"
# Begin Group "Source Files"

# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File

SOURCE=.\mmsound.c
# End Source File
# Begin Source File

SOURCE=.\mmsound.def
# End Source File
# End Group
# Begin Group "Header Files"

# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"

# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list