![]() |
|
ArkBlast Countdown - Console Game - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework) +--- Thread: ArkBlast Countdown - Console Game (/Thread-ArkBlast-Countdown-Console-Game) |
RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-18-2013 Since I can only play one sound at a time, my idea was to stop the bgm, play the sound, then play the bgm at the last location. Unfortunately, even this has been a pain in the a$$. What I tried to do was take the stream, decode it, find the offset, take that portion of the stream, re-write the WAV header to the front, and play it back. This is not good though... I didn't get any suggestions still, so I'm still working on seeing what I can do about this, avoiding DirectX until I run out of any other options. Implementing DirectX at this point would be a bit of work. RE: ArkBlast Countdown - Console Game - noize - 05-18-2013 (05-18-2013, 01:36 AM)ArkPhaze Wrote: Since I can only play one sound at a time, my idea was to stop the bgm, play the sound, then play the bgm at the last location. Unfortunately, even this has been a pain in the a$$. What I tried to do was take the stream, decode it, find the offset, take that portion of the stream, re-write the WAV header to the front, and play it back. This is not good though... I didn't get any suggestions still, so I'm still working on seeing what I can do about this, avoiding DirectX until I run out of any other options. Implementing DirectX at this point would be a bit of work. Have you tried playing the sound in another instance? I mean, this is your game: Code: start
codes you need to play sounds
play bgm
stop bgm
play soundA
restart bgm
stop bgm
endYou could add a stub like this: Code: start
codes you need to play sounds
play sound
endAnd your game: Code: start
codes you need to play sound
play bgm
replace stub's "play sound" with "play soundA"
start stub in another instance
stop bgm
endDon't know if you can make this, surely I can't, but maybe it's an idea. RE: ArkBlast Countdown - Console Game - noize - 05-18-2013 (05-18-2013, 01:36 AM)ArkPhaze Wrote: Since I can only play one sound at a time, my idea was to stop the bgm, play the sound, then play the bgm at the last location. Unfortunately, even this has been a pain in the a$$. What I tried to do was take the stream, decode it, find the offset, take that portion of the stream, re-write the WAV header to the front, and play it back. This is not good though... I didn't get any suggestions still, so I'm still working on seeing what I can do about this, avoiding DirectX until I run out of any other options. Implementing DirectX at this point would be a bit of work. Have you tried playing the sound in another instance? I mean, this is your game: Code: start
codes you need to play sounds
play bgm
stop bgm
play soundA
restart bgm
stop bgm
endYou could add a stub like this: Code: start
codes you need to play sounds
play sound
endAnd your game: Code: start
codes you need to play sound
play bgm
replace stub's "play sound" with "play soundA"
start stub in another instance
stop bgm
endDon't know if you can make this, surely I can't, but maybe it's an idea. RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-18-2013 Yeah, the function that the SoundPlayer is a wrapper for just doesn't support concurrent streams being played. You can have 2 SoundPlayer instances, and try to play different sounds on different threads, and it still won't work. I can do this: Code: play bgm
stop bgm
play soundA
restart bgm
stop bgmBecause as soon as I play soundA with bgm playing, bgm will stop to allow soundA to play, and then if I was to play bgm again, soundA would stop. I want to be able to play multiple sounds at once though... Or at least play the background music, pause it at the last location before a quick sound plays, and resume. Right now If I replay something I have to start playing it from 0:00 again. I'm using the OGG file format, reading the file into a stream, decoding that, writing it into a playable format for the stream, and playing it. Thanks for the help though No one else seems to want to provide suggestions lol. That's all I'm looking for.
RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-18-2013 Yeah, the function that the SoundPlayer is a wrapper for just doesn't support concurrent streams being played. You can have 2 SoundPlayer instances, and try to play different sounds on different threads, and it still won't work. I can do this: Code: play bgm
stop bgm
play soundA
restart bgm
stop bgmBecause as soon as I play soundA with bgm playing, bgm will stop to allow soundA to play, and then if I was to play bgm again, soundA would stop. I want to be able to play multiple sounds at once though... Or at least play the background music, pause it at the last location before a quick sound plays, and resume. Right now If I replay something I have to start playing it from 0:00 again. I'm using the OGG file format, reading the file into a stream, decoding that, writing it into a playable format for the stream, and playing it. Thanks for the help though No one else seems to want to provide suggestions lol. That's all I'm looking for.
RE: ArkBlast Countdown - Console Game - noize - 05-18-2013 (05-18-2013, 10:42 AM)ArkPhaze Wrote: Yeah, the function that the SoundPlayer is a wrapper for just doesn't support concurrent streams being played. You can have 2 SoundPlayer instances, and try to play different sounds on different threads, and it still won't work. Well, I think this is even pretty though stuff for most of the coders here on this forum (I'm included). Maybe you could use something else other than SoundPlayer. SoundPlayer to play bgm and a SoundPlayer-like thing to play different sounds. Is it possible? RE: ArkBlast Countdown - Console Game - noize - 05-18-2013 (05-18-2013, 10:42 AM)ArkPhaze Wrote: Yeah, the function that the SoundPlayer is a wrapper for just doesn't support concurrent streams being played. You can have 2 SoundPlayer instances, and try to play different sounds on different threads, and it still won't work. Well, I think this is even pretty though stuff for most of the coders here on this forum (I'm included). Maybe you could use something else other than SoundPlayer. SoundPlayer to play bgm and a SoundPlayer-like thing to play different sounds. Is it possible? RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-18-2013 I haven't attempted, but I don't think so... The only way I can think of it being possible is to modify the stream and re-write the playback headers. I would love to not have DirectX as a requirement for this game though if I can help it. It would be good to use though... The trouble is this game is in C#, managed DirectX is a hassle, and that's why it's usually done with C++. (I'll provide you guys a preview of where I am at so far with everything tomorrow in a video preview... It's early morning, and so I'm off to dreamland. )Appreciate the efforts @noize! Nobody else has tried, so credits to you. I'm just open to suggestions... RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-18-2013 I haven't attempted, but I don't think so... The only way I can think of it being possible is to modify the stream and re-write the playback headers. I would love to not have DirectX as a requirement for this game though if I can help it. It would be good to use though... The trouble is this game is in C#, managed DirectX is a hassle, and that's why it's usually done with C++. (I'll provide you guys a preview of where I am at so far with everything tomorrow in a video preview... It's early morning, and so I'm off to dreamland. )Appreciate the efforts @noize! Nobody else has tried, so credits to you. I'm just open to suggestions... RE: ArkBlast Countdown - Console Game - noize - 05-18-2013 Found this here: http://www.cplusplus.com/forum/windows/29294/ . Code: #include <windows.h>
#include <mmsystem.h>
#include <stdlib.h>
#pragma comment(lib, "winmm.lib")
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// Colors, brushes and fonts used.
COLORREF AquaBlue = RGB(51,255,204), yellow = RGB(255,255,102);
HBRUSH AquaBluebr = CreateSolidBrush(AquaBlue);
HFONT sysfont=static_cast<HFONT>(GetStockObject(SYSTEM_FONT));
// sound clips used
LPCTSTR soundA = L"AudioClips\\GameOpen.wav";
LPCTSTR soundB = L"AudioClips\\gOneShot.wav";
LPCTSTR soundC = L"AudioClips\\rocketFire.wav";
LPCTSTR soundD = L"AudioClips\\airWrench.wav";
LPCTSTR soundE = L"AudioClips\\levelBK1.wav";
LPCTSTR soundF = L"AudioClips\\levelBK2.wav";
LPCTSTR soundG = L"AudioClips\\levelBK3.wav";
HDC hdc;
static HINSTANCE hInst;
int APIENTRY WinMain(HINSTANCE hinst,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG lpmsg;
WNDCLASSEX wc = {0};
static wchar_t szAppName[] = L"playSoundShell.app";
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpszClassName = szAppName;
wc.hInstance = hinst;
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wc.lpszMenuName = 0;
wc.hbrBackground = AquaBluebr;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( !RegisterClassEx (&wc) )
return 0;
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,szAppName,L"playSoundShell",
WS_OVERLAPPEDWINDOW,200,200,640,// started at 600
480,NULL,NULL,hinst,NULL );
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&lpmsg,NULL,0,0) )
{
TranslateMessage(&lpmsg);
DispatchMessage(&lpmsg);
}//End Message Loop.
return(lpmsg.wParam);
// TODO: Place code here.
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
static POINTS pt,sz={300,300};
RECT rect;
char ch;
int j=0;// for looping.
switch(msg)
{
case WM_CREATE:
hInst = ((LPCREATESTRUCT) lParam) -> hInstance;
return 0 ;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
ValidateRect(hwnd, NULL);
GetClientRect (hwnd, &rect) ;
TextOut(hdc, 100, 100, L"This is a project shell with working playSound calls", 52);
EndPaint(hwnd, &ps);
return 0;
case WM_CHAR:// Handles keyboard events.
ch = wParam;
ch = tolower(ch);
switch( ch )
{
case 'a':// non-looping clips
PlaySound((LPCTSTR) soundA, NULL, SND_FILENAME | SND_ASYNC);
break;
case 'b':
PlaySound((LPCTSTR) soundB, NULL, SND_FILENAME | SND_ASYNC);
break;
case 'c':
PlaySound((LPCTSTR) soundC, NULL, SND_FILENAME | SND_ASYNC);
break;
case 'd':
PlaySound((LPCTSTR) soundD, NULL, SND_FILENAME | SND_ASYNC);
break;
case 'e':// looping clips
PlaySound((LPCTSTR) soundE, NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
break;
case 'f':
PlaySound((LPCTSTR) soundF, NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
break;
case 'g':
PlaySound((LPCTSTR) soundG, NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
break;
case 's':
PlaySound(NULL, 0, 0);// stops playback of clip
break;
case VK_ESCAPE:// terminate app.
PostQuitMessage(0);
break;
default:
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return( DefWindowProc(hwnd, msg, wParam, lParam) );
break;
}//End Switch on msg.
return(0);
}//End CALLBACK.I think I would use something like this to make different stubs (one for each audio file) and run it when needed. |