Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 12.08.2009, 13:45   #1
GodSmack
 
Аватар для GodSmack
 
Регистрация: 25.04.2009
Сообщений: 2
Сообщение Воспроизведение нескольких звуков одновременно

Кто-нибудь знает как стандартными средствами Windows воспроизвести несколько звуков одновременно(3-4 звука)? Пробовал OpenAl, но что-то с ним ничего не срослось, не работает он так как описано здесь http://dg.isgreat.org/OpenAL/?go=l3, да и качество воспроизведения оставляет желать лучшего.
Процедура PlaySound('sound.wav',0,1) конечно хороша, но один звук сразу же исключает другой. Может, неправильно заданы параметры процедуры(...,0,1)?
GodSmack вне форума Ответить с цитированием
Старый 12.08.2009, 14:06   #2
Пепел Феникса
Старожил
 
Аватар для Пепел Феникса
 
Регистрация: 28.01.2009
Сообщений: 21,000
По умолчанию

Цитата:
BOOL PlaySound(LPCSTR pszSound, HMODULE hmod, DWORD fdwSound);



Plays a sound specified by the given filename, resource, or system event. (A system event may be associated with a sound in the registry or in the WIN.INI file.)

· Returns TRUE if successful or FALSE otherwise.

pszSound

A string that specifies the sound to play. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter.
Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is interpreted as an alias for a system event, a filename, or a resource identifier. If none of these flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the specified sound name. If an association is found, the sound event is played. If no association is found in the registry, the name is interpreted as a filename.

hmod

Handle of the executable file that contains the resource to be loaded. This parameter must be NULL unless SND_RESOURCE is specified in fdwSound.

fdwSound

Flags for playing the sound. The following values are defined:

SND_APPLICATION

The sound is played using an application-specific association.

SND_ALIAS

The pszSound parameter is a system-event alias in the registry or the WIN.INI file. Do not use with either SND_FILENAME or SND_RESOURCE.

SND_ALIAS_ID

The pszSound parameter is a predefined sound identifier.

SND_ASYNC

The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

SND_FILENAME

The pszSound parameter is a filename.

SND_LOOP

The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL. You must also specify the SND_ASYNC flag to indicate an asynchronous sound event.

SND_MEMORY

A sound event's file is loaded in RAM. The parameter specified by pszSound must point to an image of a sound in memory.

SND_NODEFAULT

No default sound event is used. If the sound cannot be found, PlaySound returns silently without playing the default sound.

SND_NOSTOP

The specified sound event will yield to another sound event that is already playing. If a sound cannot be played because the resource needed to generate that sound is busy playing another sound, the function immediately returns FALSE without playing the requested sound.
If this flag is not specified, PlaySound attempts to stop the currently playing sound so that the device can be used to play the new sound.

SND_NOWAIT

If the driver is busy, return immediately without playing the sound.

SND_PURGE

Sounds are to be stopped for the calling task. If pszSound is not NULL, all instances of the specified sound are stopped. If pszSound is NULL, all sounds that are playing on behalf of the calling task are stopped.
You must also specify the instance handle to stop SND_RESOURCE events.

SND_RESOURCE

The pszSound parameter is a resource identifier; hmod must identify the instance that contains the resource.

SND_SYNC

Synchronous playback of a sound event. PlaySound returns after the sound event completes.

The sound specified by pszSound must fit into available physical memory and be playable by an installed waveform-audio device driver. PlaySound searches the following directories for sound files: the current directory; the Windows directory; the Windows system directory; directories listed in the PATH environment variable; and the list of directories mapped in a network. For more information about the directory search order, see the documentation for the OpenFile function.

If it cannot find the specified sound, PlaySound uses the default system event sound entry instead. If the function can find neither the system default entry nor the default sound, it makes no sound and returns FALSE.
держи, разбирайся:D
Хорошо поставленный вопрос это уже половина ответа. | Каков вопрос, таков ответ.
Программа делает то что написал программист, а не то что он хотел.
Функции/утилиты ждут в параметрах то что им надо, а не то что вы хотите.
Пепел Феникса вне форума Ответить с цитированием
Старый 12.08.2009, 14:29   #3
GodSmack
 
Аватар для GodSmack
 
Регистрация: 25.04.2009
Сообщений: 2
По умолчанию

Спасибо, но ты мне ничем не помог, я так и не понял как это сделать

Не, реально мне вот эта тема помогла:
Код:
unit SoundUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, al, altypes, alut,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Play: TButton;
    Stop: TButton;
    Pause: TButton;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure PlayClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure StopClick(Sender: TObject);
    procedure PauseClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
  numbuffers = 3;
  numsources = 3;
  walk = 0;
  ding = 1;
  zap = 2;

var
  Form1: TForm1;

  buffer : array [0..numbuffers] of TALuint;
  source : array [0..numsources] of TALuint;
  sourcepos: array [0..2] of TALfloat= ( -5.0, 0.0, -5.0 );
  sourcevel: array [0..2] of TALfloat= ( 0.5, 0.0, 0.5 );
  listenerpos: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0);
  listenervel: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0);
  listenerori: array [0..5] of TALfloat= ( 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  argv: array of PChar;
  format: TALEnum;
  size: TALSizei;
  freq: TALSizei;
  loop: TALInt;
  data: TALVoid;

begin
  AlutInit(nil,argv);

  AlGenBuffers(numbuffers, @buffer);
  AlutLoadWavFile('footsteps.wav', format, data, size, freq, loop);
  AlBufferData(buffer[walk], format, data, size, freq);
  AlutUnloadWav(format, data, size, freq);

  AlutLoadWavFile('ding.wav', format, data, size, freq, loop);
  AlBufferData(buffer[ding], format, data, size, freq);
  AlutUnloadWav(format, data, size, freq);

  AlutLoadWavFile('phaser.wav', format, data, size, freq, loop);
  AlBufferData(buffer[zap], format, data, size, freq);
  AlutUnloadWav(format, data, size, freq);

  AlGenSources(numsources, @source);
  AlSourcei ( source[walk], AL_BUFFER, buffer[walk]);
  AlSourcef ( source[walk], AL_PITCH, 1.0 );
  AlSourcef ( source[walk], AL_GAIN, 1.5 );
  AlSourcefv ( source[walk], AL_POSITION, @sourcepos);
  AlSourcefv ( source[walk], AL_VELOCITY, @sourcevel);
  AlSourcei ( source[walk], AL_LOOPING, AL_TRUE);

  SourcePos[0] := 8.0;
  SourcePos[1] := 1.0;
  SourcePos[2] := -8.0;
  AlSourcei ( source[ding], AL_BUFFER, buffer[ding]);
  AlSourcef ( source[ding], AL_PITCH, 1.0 );
  AlSourcef ( source[ding], AL_GAIN, 0.2 );
  AlSourcefv ( source[ding], AL_POSITION, @sourcepos);
  AlSourcefv ( source[ding], AL_VELOCITY, @sourcevel);
  AlSourcei ( source[ding], AL_LOOPING, AL_TRUE);

  SourcePos[0] := -8.0;
  SourcePos[1] := 1.0;
  SourcePos[2] := 8.0;
  AlSourcei ( source[zap], AL_BUFFER, buffer[zap]);
  AlSourcef ( source[zap], AL_PITCH, 1.0 );
  AlSourcef ( source[zap], AL_GAIN, 0.2 );
  AlSourcefv ( source[zap], AL_POSITION, @sourcepos);
  AlSourcefv ( source[zap], AL_VELOCITY, @sourcevel);
  AlSourcei ( source[zap], AL_LOOPING, AL_TRUE);

  AlListenerfv ( AL_POSITION, @listenerpos);
  AlListenerfv ( AL_VELOCITY, @listenervel);
  AlListenerfv ( AL_ORIENTATION, @listenerori);
end;

procedure TForm1.PlayClick(Sender: TObject);
begin
  AlSourcePlay(source[walk]);
  AlSourcePlay(source[ding]);
  AlSourcePlay(source[zap]);
  Timer1.Enabled:=True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  AlDeleteBuffers(1, @buffer);
  AlDeleteSources(1, @source);
  AlutExit();
end;

procedure TForm1.StopClick(Sender: TObject);
begin
  Timer1.Enabled:=False;
  AlSourceStop(source[walk]);
  AlSourceStop(source[ding]);
  AlSourceStop(source[zap]);
end;

procedure TForm1.PauseClick(Sender: TObject);
begin
  AlSourcePause(source[walk]);
  AlSourcePause(source[ding]);
  AlSourcePause(source[zap]);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  SourcePos[0] := SourcePos[0] + SourceVel[0];
  SourcePos[1] := SourcePos[1] + SourceVel[1];
  SourcePos[2] := SourcePos[2] + SourceVel[2];
  If SourcePos[0] >= 5 then SourcePos[0]:=-5;
  If SourcePos[2] >= 5 then SourcePos[2]:=-5;
  alSourcefv(source[walk], AL_POSITION, @SourcePos);
end;

end.

Последний раз редактировалось Stilet; 13.08.2009 в 08:11.
GodSmack вне форума Ответить с цитированием
Старый 13.08.2009, 02:28   #4
uberchel
Участник клуба
 
Аватар для uberchel
 
Регистрация: 19.01.2009
Сообщений: 1,453
По умолчанию

GodSmack !
Cамый простой способ проиграть midi, wav, mp3, xm, aiff, cda, avi, au через MCI !

Код:
uses MMSystem;
...
procedure TForm1.btn1Click(Sender: TObject);
begin
mciSendString(PChar('Play "C:\Windows\Media\notify.wav"'),nil,0,0);
mciSendString(PChar('Play "C:\Windows\Media\tada.wav"'),nil,0,0);
mciSendString(PChar('close waveaudio'),nil,0,0);
end;

Последний раз редактировалось uberchel; 13.08.2009 в 06:35.
uberchel вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Сравнение звуков MakarovAlv Помощь студентам 1 26.06.2009 16:13
Чем воспроизводить очередь звуков? Shadow_1329 Gamedev - cоздание игр: Unity, OpenGL, DirectX 21 05.05.2009 20:03
Склеивание звуков varvara16 Мультимедиа в Delphi 24 14.11.2008 18:24
Диаграммы звуков Kor Мультимедиа в Delphi 1 30.09.2008 22:43