C4 Engine

Facebook Twitter Google+ YouTube IndieDB
News Explore
Download Demo
Feature List
Licensing Info
Screenshots
Video
Support
Support Forums
C4 Engine Wiki
API Documentation
Release Notes
Purchase My Account

Overlapping the Same Sound

Topics about programming sound effects and music in the C4 Engine.

Overlapping the Same Sound

Postby a2k » 04 Oct 2011, 02:19

Is it possible to do this?

I use
Code: Select all
OmniSource* source = new OmniSource(...)
node->AddNewSubnode(source)


If this played say, a wave file that was 1 second long, but called it like 3 times a second, the subsequent 2 times would not start. What can I do to play overlapping sounds using the same sound resource?
Intel Core2 Quad Q8200 @ 2.33GHz, 4 GB RAM, nVidia 9800 GT 512 MB, Win 7 64, Visual C++ 2010 Express
User avatar
a2k
Community Leader
Community Leader
 
Posts: 2947
Joined: 25 Sep 2006, 21:35
Location: CA, USA

Re: Overlapping the Same Sound

Postby Eric Lengyel » 04 Oct 2011, 02:28

You'd need to create three separate sources. The sound resource will not be loaded more than once.
User avatar
Eric Lengyel
Terathon Employee
Terathon Employee
 
Posts: 18715
Joined: 09 May 2005, 19:00
Location: Roseville, CA

Re: Overlapping the Same Sound

Postby a2k » 04 Oct 2011, 02:45

Eric Lengyel wrote:You'd need to create three separate sources.


I'm calling new OmniSource 3 times at the point that they should play. Is this not the same as creating three separate sources?
Intel Core2 Quad Q8200 @ 2.33GHz, 4 GB RAM, nVidia 9800 GT 512 MB, Win 7 64, Visual C++ 2010 Express
User avatar
a2k
Community Leader
Community Leader
 
Posts: 2947
Joined: 25 Sep 2006, 21:35
Location: CA, USA

Re: Overlapping the Same Sound

Postby Eric Lengyel » 04 Oct 2011, 03:27

Yes, that is creating three separate sources.
User avatar
Eric Lengyel
Terathon Employee
Terathon Employee
 
Posts: 18715
Joined: 09 May 2005, 19:00
Location: Roseville, CA

Re: Overlapping the Same Sound

Postby a2k » 04 Oct 2011, 10:49

Eric Lengyel wrote:Yes, that is creating three separate sources.


To clarify, this is what I was doing. I did a test which makes a sound 10 times in succession, about 300 ms apart. I played an OmniSource with a 0.1 second wav resource. This played as expected; 10 times at 300 ms intervals. I then swapped in a 3.0 second wav resource (the same 0.1 second sound with 3.0 seconds of silence afterward), and then this played only once.
Intel Core2 Quad Q8200 @ 2.33GHz, 4 GB RAM, nVidia 9800 GT 512 MB, Win 7 64, Visual C++ 2010 Express
User avatar
a2k
Community Leader
Community Leader
 
Posts: 2947
Joined: 25 Sep 2006, 21:35
Location: CA, USA

Re: Overlapping the Same Sound

Postby Eric Lengyel » 04 Oct 2011, 11:44

We play overlapping instances of the same sound all the time in the demo without issue. Can you show me some code?
User avatar
Eric Lengyel
Terathon Employee
Terathon Employee
 
Posts: 18715
Joined: 09 May 2005, 19:00
Location: Roseville, CA

Re: Overlapping the Same Sound

Postby a2k » 05 Oct 2011, 02:19

Actually, I was able to track this down to a few things. Mainly, I was most likely creating too many Sources in my Move function. I isolated the test to a single controller, and it seems to call correctly. The other problem I have is that the audio exported from Audacity is not working as expected after adding a few seconds of silence.
Intel Core2 Quad Q8200 @ 2.33GHz, 4 GB RAM, nVidia 9800 GT 512 MB, Win 7 64, Visual C++ 2010 Express
User avatar
a2k
Community Leader
Community Leader
 
Posts: 2947
Joined: 25 Sep 2006, 21:35
Location: CA, USA

Re: Overlapping the Same Sound

Postby DeRatizator » 07 Oct 2011, 13:57

a2k wrote:Actually, I was able to track this down to a few things. Mainly, I was most likely creating too many Sources in my Move function. I isolated the test to a single controller, and it seems to call correctly. The other problem I have is that the audio exported from Audacity is not working as expected after adding a few seconds of silence.


You shouldn't use multiple sources for a rapid fire. You will run into the same weirdness as the tech demo. Yes, from Eric's point of view there is no issue but people who tried VoH, when it used such approach, disagree. They definitely perceived some "issues".
AI
User avatar
DeRatizator
Power User
Power User
 
Posts: 1470
Joined: 23 Apr 2006, 19:00
Location: Latvia

Re: Overlapping the Same Sound

Postby a2k » 07 Oct 2011, 14:01

DeRatizator wrote:
a2k wrote:Actually, I was able to track this down to a few things. Mainly, I was most likely creating too many Sources in my Move function. I isolated the test to a single controller, and it seems to call correctly. The other problem I have is that the audio exported from Audacity is not working as expected after adding a few seconds of silence.


You shouldn't use multiple sources for a rapid fire. You will run into the same weirdness as the tech demo. Yes, from Eric's point of view there is no issue but people who tried VoH, when it used such approach, disagree. They definitely perceived some "issues".


Well, my post should have read I was most likely creating too many *unnecessary* Sources in my Move function. The code was rather infantile, so I may have missed an if statement or two when called new. Unfortunately, I'm not going to try using a single source for this sort of thing, because think of it more like a row of dominoes being knocked over, rather than a minigun.
Intel Core2 Quad Q8200 @ 2.33GHz, 4 GB RAM, nVidia 9800 GT 512 MB, Win 7 64, Visual C++ 2010 Express
User avatar
a2k
Community Leader
Community Leader
 
Posts: 2947
Joined: 25 Sep 2006, 21:35
Location: CA, USA

Re: Overlapping the Same Sound

Postby MACK » 07 Jun 2012, 01:39

Not sure if this is relevant, but we discovered too many sounds seem to overwhelm the sound card / audio device, so we track sounds that have a high risk of repeating often, and limit them to a certain # of concurrent plays.
For example loud explosive sounds that are slow to decay we cap at around 5 concurrent.
New C4 Book Here!
EVGA SR2 Mb @(2.4 to 3.4 Ghz), Intel E5620 dual cpu, 4x4GB ECC RAM, OS ADATA S511 256GB RAID10
Nvidia GTX660, Driver 320.49 WHQL Win7 64bit, DX SDK 6-10
skype ck_mack
MACK
Community Leader
Community Leader
 
Posts: 1647
Joined: 05 Oct 2008, 01:53
Location: Salisbury, NC USA

Re: Overlapping the Same Sound

Postby Eric Lengyel » 07 Jun 2012, 01:43

MACK wrote:Not sure if this is relevant, but we discovered too many sounds seem to overwhelm the sound card / audio device, so we track sounds that have a high risk of repeating often, and limit them to a certain # of concurrent plays.


C4 only sends a single sound to the hardware, and it's always streaming a single ring buffer no matter what. So it's never possible to run into any problems with sound cards. If you're noticing dropped sounds, it's because you've reached the engine's internal limit, and the engine is resorting to completing sounds immediately because it has nowhere to stick them.
User avatar
Eric Lengyel
Terathon Employee
Terathon Employee
 
Posts: 18715
Joined: 09 May 2005, 19:00
Location: Roseville, CA

Re: Overlapping the Same Sound

Postby MACK » 07 Jun 2012, 01:51

That's great info.

I am not sure how to tell if its a buffer issue, vs just having too many concurrent sounds simply sounds "bad".

I won't really be able to determine the answer unless I can check to see if the buffer is at its limit.
Could I look for a flag as to whether or not the engine has run out of buffer? Or a way to check for the buffer's current usage?
(It would useful because then I might be able to simply allow more sounds to play until the buffer fills, rather than cap the # of concurrent effects in a hard way.)


Thanks.
New C4 Book Here!
EVGA SR2 Mb @(2.4 to 3.4 Ghz), Intel E5620 dual cpu, 4x4GB ECC RAM, OS ADATA S511 256GB RAID10
Nvidia GTX660, Driver 320.49 WHQL Win7 64bit, DX SDK 6-10
skype ck_mack
MACK
Community Leader
Community Leader
 
Posts: 1647
Joined: 05 Oct 2008, 01:53
Location: Salisbury, NC USA

Re: Overlapping the Same Sound

Postby Eric Lengyel » 07 Jun 2012, 02:03

It's not buffer space that the engine runs out of, but slots for currently playing sounds. There's a fixed-size table whose number of entries is defined by kMaxSoundCount in C4Sound.h.

If you're hearing distortion, it could just be because a lot of loud sounds are being mixed together at the same time.
User avatar
Eric Lengyel
Terathon Employee
Terathon Employee
 
Posts: 18715
Joined: 09 May 2005, 19:00
Location: Roseville, CA


Return to Audio Programming

Who is online

Users browsing this forum: No registered users and 0 guests

Company Contact Privacy Policy Site Map Copyright © 2001–2014 Terathon Software LLC Terathon Software