some general questions about sounds
-
Hello, I have a few general questions about how to go about implementing sounds in my application. I have created a dictionary program with english and spanish words. It uses an Access database to store the dictionary information. I want to record sound clips of all of the spanish words (about 600 of them), and allow the user to push a button to hear the pronunciation of the word. First of all, does anyone have any opinions on what the best way to implement sound would be. Should I use wav files and use the playsound from the Windows API, or should I use DirectSound, or should I try something else like the nBASS library? I basically just want the easiest way to play sounds, and I don't want to take up too much space on the user's computer. Also, would it be best to embed the sounds in the database, or to have them as external files in the application folder? Any suggestions would be helpful. Thanks! Blake
-
Hello, I have a few general questions about how to go about implementing sounds in my application. I have created a dictionary program with english and spanish words. It uses an Access database to store the dictionary information. I want to record sound clips of all of the spanish words (about 600 of them), and allow the user to push a button to hear the pronunciation of the word. First of all, does anyone have any opinions on what the best way to implement sound would be. Should I use wav files and use the playsound from the Windows API, or should I use DirectSound, or should I try something else like the nBASS library? I basically just want the easiest way to play sounds, and I don't want to take up too much space on the user's computer. Also, would it be best to embed the sounds in the database, or to have them as external files in the application folder? Any suggestions would be helpful. Thanks! Blake
Any of those libraries deal with WAV files, and your WAV files will pretty much be the same size depending on recording quality. As we discussed before, if you want to decrease the size you'll need to encode them as MP3s, OGGs, WMAs, or whatever. As far as storing them in the database, it's just my opinion that this would add a lot of complexity because you have to (in most cases) get a "pointer" to the data and use a stream to save the file (perhaps just to memory) so that it could be played. Perhaps there's an easier way, but simplying playing a persistent file would be easier. In either case, the file will take up about the same amount of room. The database (at least Access) won't compress the contents, so it would be the same size in the database that it would be on disk. The only difficulty with the disk approach is that your database probably shouldn't store absolute paths (to work in any case and in any location) so your program should resolve the path to the same file. For instance, lets say you store the path relative to the application's installation directory. You could then do a simple
Path.Combine
:string relpath = path_from_database;
string path = Path.Combine(Application.StartupPath, relpath);
PlaySound(path); // Made-up function name, of course-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Any of those libraries deal with WAV files, and your WAV files will pretty much be the same size depending on recording quality. As we discussed before, if you want to decrease the size you'll need to encode them as MP3s, OGGs, WMAs, or whatever. As far as storing them in the database, it's just my opinion that this would add a lot of complexity because you have to (in most cases) get a "pointer" to the data and use a stream to save the file (perhaps just to memory) so that it could be played. Perhaps there's an easier way, but simplying playing a persistent file would be easier. In either case, the file will take up about the same amount of room. The database (at least Access) won't compress the contents, so it would be the same size in the database that it would be on disk. The only difficulty with the disk approach is that your database probably shouldn't store absolute paths (to work in any case and in any location) so your program should resolve the path to the same file. For instance, lets say you store the path relative to the application's installation directory. You could then do a simple
Path.Combine
:string relpath = path_from_database;
string path = Path.Combine(Application.StartupPath, relpath);
PlaySound(path); // Made-up function name, of course-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Thanks for the information. The main reason that I thought about storing the sounds in the database is to keep from having 600 individual wav files in the application folder, so that it seems neater. Do you think this would matter at all? Blake
Not really, no. NTFS does a lot better job of many files in a directory. Overall, I would think, it'd still be faster than having to stream BLOBs froma database. I've never done this myself, though (never had a reason to), and have only read about it for the SQL classes (presume that OLE DB would be a little more cumbersome because it's generic - if even possible). As far as the "application folder", I would create a subdirectory (if you choose this approach) to hold them so it doesn't clutter the application directory itself. This is pretty common in a lot of applications (take Office and its directory structure, for example).
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Not really, no. NTFS does a lot better job of many files in a directory. Overall, I would think, it'd still be faster than having to stream BLOBs froma database. I've never done this myself, though (never had a reason to), and have only read about it for the SQL classes (presume that OLE DB would be a little more cumbersome because it's generic - if even possible). As far as the "application folder", I would create a subdirectory (if you choose this approach) to hold them so it doesn't clutter the application directory itself. This is pretty common in a lot of applications (take Office and its directory structure, for example).
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Heath Stewart wrote: NTFS does a lot better job of many files in a directory. As long as that many is below 10000, after that it starts choking... :sigh: leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it. -
Hello, I have a few general questions about how to go about implementing sounds in my application. I have created a dictionary program with english and spanish words. It uses an Access database to store the dictionary information. I want to record sound clips of all of the spanish words (about 600 of them), and allow the user to push a button to hear the pronunciation of the word. First of all, does anyone have any opinions on what the best way to implement sound would be. Should I use wav files and use the playsound from the Windows API, or should I use DirectSound, or should I try something else like the nBASS library? I basically just want the easiest way to play sounds, and I don't want to take up too much space on the user's computer. Also, would it be best to embed the sounds in the database, or to have them as external files in the application folder? Any suggestions would be helpful. Thanks! Blake
blakeb_1 wrote: I want to record sound clips of all of the spanish words (about 600 of them), I suggest as Heath said a database would be good, seeing that maintainance will be easier. Another option is to make a binary container file with a header specifying offsets to the soundfiles. nBASS allows you to play a sound clip straight from a MemoryStream. leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it. -
blakeb_1 wrote: I want to record sound clips of all of the spanish words (about 600 of them), I suggest as Heath said a database would be good, seeing that maintainance will be easier. Another option is to make a binary container file with a header specifying offsets to the soundfiles. nBASS allows you to play a sound clip straight from a MemoryStream. leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it. -
nBASS[^] (you'll notice that leppie wrote it)
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
nBASS[^] (you'll notice that leppie wrote it)
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Actually I was talking about information for making a binary container file. Is this the actual name for these types of files. I searched for it in Google but couldn't find anything that looked like it was a way to store all the sounds in one file. I'm just trying to find a reference for making a binary container file. Blake
-
Actually I was talking about information for making a binary container file. Is this the actual name for these types of files. I searched for it in Google but couldn't find anything that looked like it was a way to store all the sounds in one file. I'm just trying to find a reference for making a binary container file. Blake
As leppie was saying, it's just a file with offsets - your typical archive type file. You could have a structure as the first blob in the file like so:
public struct Header
{
public int count;
public FileHeader[] headers;
}
public struct FileHeader
{
public string Filename;
public long Offset;
public long Length;
}You fill the
Header
structure with information, such as how many files are in the archive and an array that represents each file. You can provide a filename (might as well) and a byte offset to where that file is found. You can get a lot more advanced than this, and even this basic example wouldn't work as well as many others out there. Basically, though, you take that offset (either from the beginning of the file (offset 0) or from the end of theHeader
(offset == size ofHeader
, including the array ofFileHeader
s), and start reading a byte array from thatOffset
untilLength
bytes has been read. There is no standard way of doing this, but I do remember seeing a couple of articles about archives here on CP. You could try googling for keywords such as archive, header, and other stuff I've used here. leppie might have some other suggestions.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----