Hey all, I've got a technical question:
I'm working on a little side project at the moment, and I thought it might be cool to use PxTone for the music. Unfortunately, I can't seem to get it to play anything, and I don't know why.
Someone over
at the doukutsu livejournal community apparently had the same problem, but his solution doesn't work for me.
Here's where I am: I'm using the pxtone dll, the pxtone.lib file, both of which come in the pxtone package on Pixel's site. I'm also using this version of pxtone.h which is translated into english, which I found through google:
#ifdef PXTONEDLL_EXPORTS
#define DLLAPI __declspec(dllexport) // Declare for DLL export
#else
#define DLLAPI __declspec(dllimport) // Declare for DLL import
#endif
// We want C instead of C++.
#ifdef __cplusplus
extern "C"{
#endif
typedef BOOL (* PXTONEPLAY_CALLBACK)( long clock );
// pxtone functions follow ===================================
// Initialise pxtone.
BOOL DLLAPI pxtone_Ready(
HWND hWnd, // Please supply window handle
long channel_num, // Please specify the number of channels (1:Mono / 2:Stereo)
long sps, // Per-second sampling rate (11025 / 22050 / 44100)
long bps, // Beat count per 1 sample ( 8 / 16 )
float buffer_sec, // Song buffer size, used to play a song (0.1 recommended)
BOOL bDirectSound, // TRUE: Use DirectSound / FALSE: Use WAVEMAPPER.
PXTONEPLAY_CALLBACK pProc // Function called for each sample. Can be NULL.
); // pxtone declaration
// Reconfigure pxtone.
BOOL DLLAPI pxtone_Reset(
HWND hWnd,
long channel_num,
long sps,
long bps,
float buffer_sec,
BOOL bDirectSound,
PXTONEPLAY_CALLBACK pProc
);
// pxtone generates a DirectSound pointer (LPDIRECTSOUND).
// Please be careful not to release DirectSound itself.
void DLLAPI *pxtone_GetDirectSound( void );
// Aquires the previous error string
const char DLLAPI* pxtone_GetLastError( void );
// Get the pxtone quality
void DLLAPI pxtone_GetQuality( long *p_channel_num, long *p_sps, long *p_bps, long *p_sample_per_buf ); // pxtone
// Release pxtone.
BOOL DLLAPI pxtone_Release( void );
// Load a song (from a resource file)
BOOL DLLAPI pxtone_Tune_Load(
HMODULE hModule, // If you are reading a resource from a module handle.
// It's no problem for this to be NULL.
const char *type_name, // The resource type if you are reading from a resource.
// For reading external files, this is NULL.
const char *file_name // Resource file name or path and filename.
);
// Load a song (from memory)
BOOL DLLAPI pxtone_Tune_Read( void* p, long size );
// Free a song
BOOL DLLAPI pxtone_Tune_Release( void );
// Play the song
BOOL DLLAPI pxtone_Tune_Start(
long start_sample, // Start position. Stop and Fadeout mainly use these values. 0 is the first.
long fadein_msec // Fade-in time from this position (milliseconds).
);
// Fade out playback starting on next sample.
long DLLAPI pxtone_Tune_Fadeout( long msec );
// Set the song volume. Up to 1.0, 0.5 is half.
void DLLAPI pxtone_Tune_SetVolume( float v );
// Stop sampling for currently playing song
long DLLAPI pxtone_Tune_Stop( void );
// Determines whether playing.
BOOL DLLAPI pxtone_Tune_IsStreaming( void );
// Set playback looping ON / OFF.
void DLLAPI pxtone_Tune_SetLoop( BOOL bLoop );
// Get information about the song.
void DLLAPI pxtone_Tune_GetInformation( long *p_beat_num, float *p_beat_tempo, long *p_beat_clock, long *p_meas_num );
// Get start-of-repeat measure.
long DLLAPI pxtone_Tune_GetRepeatMeas( void );
// Get the effective performance measure (LAST event measure, if you do not have a final measure)
long DLLAPI pxtone_Tune_GetPlayMeas( void );
// Get the name of the song.
const char DLLAPI* pxtone_Tune_GetName( void );
// Get the song comments.
const char DLLAPI* pxtone_Tune_GetComment( void );
// Specifies address to which to write playback buffer
BOOL DLLAPI pxtone_Tune_Vomit(
void* p, // The address of the playback buffer
long sample_num // Number of samples to write
);
// Returns: TRUE if you have not yet continued, FALSE otherwise
// 1. If you use this function, please set buffer_sec of pxtone_Ready() to 0.
// pxtone streaming feature is disabled.
// 2. After a call to this function, call pxtone_Tune_Start() to load song.
// 3. sample_num sample size is not the sample number.
// Ex) 11025hz 2ch 8bit will spit out a double value, even though sample_num
// specifies 11025. 22050 bytes are written to the playback buffer.
// 4. Streaming functions are similarly valid, e.g. pxtone_Tune_Fadeout().
#ifdef __cplusplus
}
#endif
I'm using Allegro, so in my program I
#include <winalleg.h> (so that I can access the windows stuff) and
#include "pxtone.h", I link in
pxtone.lib, and in the main code I do the following, which should load and play the song: (win_get_window() is an allegro function to return the window handler)
char* song = "mysong.pttune";
pxtone_Ready(win_get_window(), 2, 44100, 16, 0.1, TRUE, NULL);
pxtone_Tune_Load(NULL, NULL, song);
pxtone_Tune_SetVolume(1.0f);
pxtone_Tune_Start(0,0);
I don't get any errors, but I don't hear anything either. Any advice?
It's probably something silly!