mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
initial checkin
This commit is contained in:
121
MAC_SDK/Compress/Sample 1/Sample 1.cpp
Normal file
121
MAC_SDK/Compress/Sample 1/Sample 1.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/***************************************************************************************
|
||||
Compress - Sample 1
|
||||
Copyright (C) 2000-2001 by Matthew T. Ashland All Rights Reserved.
|
||||
Feel free to use this code in any way that you like.
|
||||
|
||||
This example illustrates using MACLib.lib to create an APE file by encoding some
|
||||
random data.
|
||||
|
||||
The IAPECompress interface fully supports on-the-fly encoding. To use on-
|
||||
the-fly encoding, be sure to tell the encoder to create the proper WAV header on
|
||||
decompression. Also, you need to specify the absolute maximum audio bytes that will
|
||||
get encoded. (trying to encode more than the limit set on Start() will cause failure)
|
||||
This maximum is used to allocates space in the seek table at the front of the file. Currently,
|
||||
it takes around 8k per hour of CD music, so it isn't a big deal to allocate more than
|
||||
needed. You can also specify MAX_AUDIO_BYTES_UNKNOWN to allocate as much space as possible. (2 GB)
|
||||
|
||||
Notes for use in a new project:
|
||||
-you need to include "MACLib.lib" in the included libraries list
|
||||
-life will be easier if you set the [MAC SDK]\\Shared directory as an include
|
||||
directory and an additional library input path in the project settings
|
||||
-set the runtime library to "Mutlithreaded"
|
||||
|
||||
WARNING:
|
||||
-This class driven system for using Monkey's Audio is still in development, so
|
||||
I can't make any guarantees that the classes and libraries won't change before
|
||||
everything gets finalized. Use them at your own risk
|
||||
***************************************************************************************/
|
||||
|
||||
// includes
|
||||
#include <windows.h>
|
||||
#include <mmreg.h>
|
||||
#include "stdio.h"
|
||||
#include "all.h"
|
||||
#include "MACLib.h"
|
||||
|
||||
/***************************************************************************************
|
||||
Main (the main function)
|
||||
***************************************************************************************/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// variable declares
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
int nAudioBytes = 1048576*10;
|
||||
const char cOutputFile[MAX_PATH] = "c:\\Noise.ape";
|
||||
|
||||
printf("Creating file: %s\n", cOutputFile);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// create and start the encoder
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// set the input WAV format
|
||||
WAVEFORMATEX wfeAudioFormat; FillWaveFormatEx(&wfeAudioFormat, 44100, 16, 2);
|
||||
|
||||
// create the encoder interface
|
||||
IAPECompress * pAPECompress = CreateIAPECompress();
|
||||
|
||||
// start the encoder
|
||||
int nRetVal = pAPECompress->Start(cOutputFile, &wfeAudioFormat, nAudioBytes,
|
||||
COMPRESSION_LEVEL_HIGH, NULL, CREATE_WAV_HEADER_ON_DECOMPRESSION);
|
||||
|
||||
if (nRetVal != 0)
|
||||
{
|
||||
SAFE_DELETE(pAPECompress)
|
||||
printf("Error starting encoder.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// pump through and feed the encoder audio data (white noise for the sample)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
int nAudioBytesLeft = nAudioBytes;
|
||||
|
||||
while (nAudioBytesLeft > 0)
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NOTE: we're locking the buffer used internally by MAC and copying the data
|
||||
// directly into it... however, you could also use the AddData(...) command
|
||||
// to avoid the added complexity of locking and unlocking
|
||||
// the buffer (but it may be a little slower )
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// lock the compression buffer
|
||||
int nBufferBytesAvailable = 0;
|
||||
unsigned char * pBuffer = pAPECompress->LockBuffer(&nBufferBytesAvailable);
|
||||
|
||||
// fill the buffer with white noise
|
||||
int nNoiseBytes = min(nBufferBytesAvailable, nAudioBytesLeft);
|
||||
for (int z = 0; z < nNoiseBytes; z++)
|
||||
{
|
||||
pBuffer[z] = rand() % 255;
|
||||
}
|
||||
|
||||
// unlock the buffer and let it get processed
|
||||
int nRetVal = pAPECompress->UnlockBuffer(nNoiseBytes, TRUE);
|
||||
if (nRetVal != 0)
|
||||
{
|
||||
printf("Error Encoding Frame (error: %d)\n", nRetVal);
|
||||
break;
|
||||
}
|
||||
|
||||
// update the audio bytes left
|
||||
nAudioBytesLeft -= nNoiseBytes;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// finalize the file (could append a tag, or WAV terminating data)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
if (pAPECompress->Finish(NULL, 0, 0) != 0)
|
||||
{
|
||||
printf("Error finishing encoder.\n");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// clean up and quit
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
SAFE_DELETE(pAPECompress)
|
||||
printf("Done.\n");
|
||||
return 0;
|
||||
}
|
||||
106
MAC_SDK/Compress/Sample 1/Sample 1.dsp
Normal file
106
MAC_SDK/Compress/Sample 1/Sample 1.dsp
Normal file
@@ -0,0 +1,106 @@
|
||||
# Microsoft Developer Studio Project File - Name="Sample 1" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=Sample 1 - 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 "Sample 1.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 "Sample 1.mak" CFG="Sample 1 - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Sample 1 - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "Sample 1 - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "Sample 1 - 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 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\Shared" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# 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 /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib maclib.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\Shared"
|
||||
|
||||
!ELSEIF "$(CFG)" == "Sample 1 - 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 /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\Shared" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# 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 /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib maclib.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\Shared"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Sample 1 - Win32 Release"
|
||||
# Name "Sample 1 - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=".\Sample 1.cpp"
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Shared\All.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Shared\MAC.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
Reference in New Issue
Block a user