📄 sound.c
字号:
/******************************************************************
* SEAL 2.0 *
* Copyright (c) 1999-2002 SEAL Developers. All Rights Reserved. *
* *
* Web site: http://sealsystem.sourceforge.net/ *
* E-mail (current maintainer): orudge@users.sourceforge.net *
******************************************************************/
/*
This program 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 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*********************************************************************
Revision History:
- 23/04/2001 Updates for Bad Seal compatible version, etc (orudge)
- 02/09/2001 Updated for SEAL 2.0 kernel include (julien)
- 16/09/2001 Updated for enhanced SFA Player (orudge)
- 04/10/2001 Added support for About command (orudge)
- 10/11/2001 Upped version to 1.0 and vastly improved API, cleaned
up code, etc - complete rewrite (orudge)
- 23/03/2002 Added space in t_soundformat_item structure for driver
instance-specific data.
- 03/03/2002 ? Integrated with SEAL 2.00.11 (orudge)
- 05/04/2002 Added send_custom_message function (orudge)
All dates are in UK format (DD/MM/YYYY)
*********************************************************************
*/
#include <seal.h>
#include <app.h>
#include <sound.h>
#ifdef ___CPL_SUPPORT // Control Panel support currently DOES NOT WORK!
#include <cp.h>
#endif
#define TXT_INITSOUNDCARD INI_TEXT("Launching sound driver: Initialising sound card...")
#define TXT_SOUNDCARD INI_TEXT("Launching sound driver: Sound card found: %s")
#define TXT_CANNOTINITSOUNDCARD INI_TEXT("Cannot initialise the soundcard: %s\n\nPlease edit allegro.cfg!\n")
#define TXT_CANNOTINITSOUNDINPUT INI_TEXT("Cannot install sound input: %s")
#ifdef ___CPL_SUPPORT
#define TXT_SFACPL INI_TEXT("SFA")
#define TXT_SFACPLSETTINGS INI_TEXT("SFA Driver Configuration")
#define TXT_SFACPLINFO INI_TEXT("Configuration of SFA drivers")
p_cp_section cpl_section;
#endif
/* sound format item functions */
p_list sound_format_list;
/*****************************************************************
Function: p_soundformat_item new_soundformat_item(<SEE BELOW>)
Adds a new format to the sound format list.
Returns a pointer to the soundformat object.
*****************************************************************/
p_soundformat_item new_soundformat_item( l_text extension,
l_text filedesc,
l_text info,
l_bool (*init_driver) (p_soundformat_item o),
l_bool (*init_file) (p_soundformat_item o, l_text file, l_bool play),
l_bool (*play_file) (p_soundformat_item o),
l_bool (*poll_file) (p_soundformat_item o),
l_bool (*stop_file) (p_soundformat_item o),
l_bool (*pause_file) (p_soundformat_item o),
l_bool (*forward_file) (p_soundformat_item o, l_int time),
l_bool (*rewind_file) (p_soundformat_item o, l_int time),
l_bool (*set_pos) (p_soundformat_item o, l_int time),
l_int (*get_pos) (p_soundformat_item o),
l_int (*get_len_file)(p_soundformat_item o),
l_bool (*get_file_info)(p_soundformat_item o, SFAINFO *inf),
l_text (*get_friendly_name)(p_soundformat_item o),
l_bool (*config_driver)(p_soundformat_item o),
l_bool (*display_about)(p_soundformat_item o),
l_bool (*close_file)(p_soundformat_item o),
l_bool (*terminate_driver)(p_soundformat_item o),
l_bool (*send_custom_message)(p_soundformat_item o, l_int msg, void *extra)
)
{
p_soundformat_item i = (p_soundformat_item)_malloc(sizeof(t_soundformat_item));
if (i)
{
i->extension = _strdup(extension);
i->info = _strdup(info); // OCR: strdup to _strdup
i->filedesc = _strdup(filedesc); // OCR: strdup to _strdup
i->init_driver = init_driver;
i->init_file = init_file;
i->play_file = play_file;
i->poll_file = poll_file;
i->stop_file = stop_file;
i->pause_file = pause_file;
i->forward_file = forward_file;
i->rewind_file = rewind_file;
i->set_pos = set_pos;
i->get_pos = get_pos;
i->get_len_file = get_len_file;
i->get_file_info = get_file_info;
i->get_friendly_name = get_friendly_name;
i->config_driver = config_driver;
i->display_about = display_about;
i->close_file = close_file;
i->terminate_driver = terminate_driver;
}
return(i);
}
void free_soundformat_item(void *o)
{
if (o)
{
if (((p_soundformat_item)o)->extension)_free(((p_soundformat_item)o)->extension);
if (((p_soundformat_item)o)->info) _free(((p_soundformat_item)o)->info);
if (((p_soundformat_item)o)->filedesc) _free(((p_soundformat_item)o)->filedesc);
_free(o);
}
}
/* Dummy functions */
l_bool st_init_driver(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_init_file(p_soundformat_item o, l_text file, l_bool play)
{
return(FALSE);
}
l_bool st_play_file(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_poll_file(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_stop_file(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_pause_file(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_forward_file(p_soundformat_item o, l_int time)
{
return(FALSE);
}
l_bool st_rewind_file(p_soundformat_item o, l_int time)
{
return(FALSE);
}
l_bool st_set_pos(p_soundformat_item o, l_int time)
{
return(FALSE);
}
l_int st_get_pos(p_soundformat_item o)
{
return(0);
}
l_int st_get_len_file(p_soundformat_item o)
{
return(0);
}
l_bool st_get_file_info(p_soundformat_item o, SFAINFO *inf)
{
return(FALSE);
}
l_text st_get_friendly_name(p_soundformat_item o)
{
return(NULL);
}
l_bool st_config_driver(p_soundformat_item o)
{
msgbox(MW_INFO, MB_OK, "This driver does not have any user-configurable options.");
return(FALSE);
}
l_bool st_display_about(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_close_file(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_terminate_driver(p_soundformat_item o)
{
return(FALSE);
}
l_bool st_send_custom_message(p_soundformat_item o, l_int msg, void *extra)
{
return(FALSE);
}
/**************************************************
Function: p_play SFA_init()
Initialises SFA and returns a p_play object.
**************************************************/
p_play SFA_init()
{
p_play p = (p_play)_malloc(sizeof(t_play));
if (p)
{
p->init_driver = &init_driver;
p->init_file = &init_file;
p->play_file = &play_file;
p->poll_file = &poll_file;
p->stop_file = &stop_file;
p->pause_file = &pause_file;
p->forward_file = &forward_file;
p->rewind_file = &rewind_file;
p->set_pos = &set_pos;
p->get_pos = &get_pos;
p->get_len_file = &get_len_file;
p->get_file_info = &get_file_info;
p->get_friendly_name = &get_friendly_name;
p->config_driver = &config_driver;
p->display_about = &display_about;
p->close_file = &close_file;
p->terminate_driver = &terminate_driver;
p->send_custom_message = &send_custom_message;
p->filename = 0;
p->used_library = 0;
}
return(p);
}
/**************************************************
Function: l_bool init_driver(p_play o)
Initialises the driver for a single session.
Returns TRUE on success, FALSE otherwise.
**************************************************/
l_bool init_driver(p_play o)
{
p_item x = sound_format_list->first(sound_format_list);
p_item f = x;
signed int ok = 0;
l_text pfile = GetFile(o->filename);
l_int used_l = 0;
o->used_library = 0;
do
{
if (!stricmp(((p_soundformat_item)x->rec)->extension, get_extension(pfile)))
{
o->used_library = (p_soundformat_item)x->rec;
ok = 1;
}
x = x->next;
} while (!ok && x != f);
if (o->used_library)
{
used_l = (o->used_library)->init_driver(o->used_library);
#ifdef ___CPL_SUPPORT
add_cp_loader((o->used_library)->filedesc, "", cpl_section, NULL, NULL, sfa_cpl_load, sfa_cpl_trans_ev, sfa_cpl_save);
#endif
}
else
{
DEBUG_printf("SFA Error: Unknown file type for \"%s\"\n", pfile);
return(FALSE);
}
if (pfile) _free(pfile);
return (used_l);
}
/**************************************************
Function: l_bool init_file(p_play o, l_text file)
Loads a file. If play is TRUE, it starts playing.
Returns TRUE on success, FALSE otherwise.
**************************************************/
l_bool init_file (p_play o, l_text file, l_bool play)
{
p_item x = sound_format_list->first(sound_format_list);
p_item f = x;
signed int ok = 0;
l_text pfile = GetFile(file);
l_int used_l = 0;
o->used_library = 0;
do
{
if (!stricmp(((p_soundformat_item)x->rec)->extension , get_extension(pfile)))
{
o->used_library = (p_soundformat_item)x->rec;
ok = 1;
}
x = x->next;
} while (!ok && x != f);
if (o->used_library)
used_l = (o->used_library)->init_file(o->used_library, pfile, play);
else
{
DEBUG_printf("SFA Error: Unknown file type for \"%s\"\n", pfile);
return(FALSE);
}
if (pfile) _free(pfile);
return(used_l);
}
/**************************************************
Function: l_bool play_file(p_play o)
Plays the file.
Returns TRUE on success, FALSE otherwise.
**************************************************/
l_bool play_file (p_play o)
{
if (o->used_library)
return((o->used_library)->play_file(o->used_library));
}
/**************************************************
Function: l_bool poll_file(p_play o)
Polls the driver. Should be called very often.
Returns TRUE on success, FALSE otherwise.
**************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -