Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. some general questions about sounds

some general questions about sounds

Scheduled Pinned Locked Moved C#
databasejsontutorialquestiondiscussion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blakeb_1
    wrote on last edited by
    #1

    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

    H L 2 Replies Last reply
    0
    • B blakeb_1

      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

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      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-----

      B 1 Reply Last reply
      0
      • H Heath Stewart

        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-----

        B Offline
        B Offline
        blakeb_1
        wrote on last edited by
        #3

        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

        H 1 Reply Last reply
        0
        • B blakeb_1

          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

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          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-----

          L 1 Reply Last reply
          0
          • H Heath Stewart

            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-----

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • B blakeb_1

              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

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              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.

              B 1 Reply Last reply
              0
              • L leppie

                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.

                B Offline
                B Offline
                blakeb_1
                wrote on last edited by
                #7

                What should I search for to find good references for doing this?

                H 1 Reply Last reply
                0
                • B blakeb_1

                  What should I search for to find good references for doing this?

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  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-----

                  B 1 Reply Last reply
                  0
                  • H Heath Stewart

                    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-----

                    B Offline
                    B Offline
                    blakeb_1
                    wrote on last edited by
                    #9

                    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

                    H 1 Reply Last reply
                    0
                    • B blakeb_1

                      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

                      H Offline
                      H Offline
                      Heath Stewart
                      wrote on last edited by
                      #10

                      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 the Header (offset == size of Header, including the array of FileHeaders), and start reading a byte array from that Offset until Length 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-----

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups