Category Archives: Audio/Video

Articles related to Audio and/or Video based programming tasks.

How to Play an Embedded Resource .Wave Sound in VB.NET 2008, Visual Basic 2010, and Newer

I’ve recenty been making an example program with Visual Basic.NET 2008 on snapping forms to the edge of the screen. I wanted the program to play a sound wave file when it performed the snapping process. But I didn’t want to have to make it link to external wave files or anything. So I decided to embed the wave sound bytes in the program itself. So this little article will show you how I went about doing that. Here is a link to the actual example application that this article is based on.

Example Playing Embedded Wave Sounds


More Info

The first thing you want to do of course is determine the wave files you want to play in your application. Remember that the size of each .wav file in bytes, willl be added to your programs file size. So remember that when you decide on what sound files you want to use.

I also want to mention that this article is specific to VB .NET 2005/2008/2010 and higher since I am using the SoundPlayer class. Visual Basic .NET 2002/2003 will have to use the PlaySound api thats part of the WinMM.dll library. The PlaySound api can play and do everything the SoundPlayer class in VB 2005 and higher can do. Just more code is involved. I actually found an article after I started this post that shows how to play wave files embedded in your VB.NET 02/03 application. Just click here to check it out.

Embedding your .Wave Files

After you have determined the wave files you want to embed in your program you need to add them to your project. There are a couple ways to do this. The easiest way is to copy your .wav file and then paste it in your project. To paste it to your project you just need to select your project name in the Solution Explorer, usually the top right panel. Then right click and click on the paste command. Another way is to click on the “Project” and click on “Add Existing Item”. Then just browse to the wave files location and select each file you want to embed. Once the files are added to your project, you will want to click on each wave file and in the properties panel (Its right below the Solution Explorer by Default). In the Properties panel you will see “Build Action”. From the build action combo list select “Embedded Resource”. Do that for each sound file you added to your project.

Playing your Embedded Files

Now that you have embedded your files into your application, its time to setup the code to play them. If your using .NET older than 2005 then check out this article on using the unManaged api call “PlaySound” to do the playback.

You now need to access your newly embedded *.wav file. You can access it as a stream under your programs manifest. Here is the method that will be used…

Public Overridable Function GetManifestResourceStream(ByVal name As String) As System.IO.Stream Continue reading

Free eBook: Patterns & Practices Application Architecture Guide 2.0

A while back Microsoft made available a new eBook for free called: Patterns and Pratices Application Architecture Guide 2.0

The download is about 3 megs of info and in the .pdf format. This book is should be very useful and helpful for .NET developers. Below are some of the features and Chapters in the free book.


Parts

Part I, Fundamentals
Part II, Design
Part III, Layers
Part IV, Archetypes

Foreword

  • Foreword by S. Somasegar
  • Foreword by Scott Guthrie

Chapters

  • Introduction
  • Architecture and Design Solutions At a Glance
  • Fast Track

 

Part I, Fundamentals

  • Chapter 1 – Fundamentals of Application Architecture
  • Chapter 2 – .NET Platform Overview
  • Chapter 3 – Architecture and Design Guidelines

   

Part II, Design

  • Chapter 4 – Designing Your Architecture
  • Chapter 5 – Deployment Patterns
  • Chapter 6 – Architectural Styles
  • Chapter 7 – Quality Attributes
  • Chapter 8 – Communication Guidelines

   

Part III, Layers

  • Chapter 9 – Layers and Tiers
  • Chapter 10 – Presentation Layer Guidelines
  • Chapter 11 – Business Layer Guidelines
  • Chapter 12 – Data Access Layer Guidelines
  • Chapter 13 – Service Layer Guidelines

   

Part IV, Archetypes

  • Chapter 14 – Application Archetypes
  • Chapter 15 – Web Applications
  • Chapter 16 – Rich Internet Applications (RIA)
  • Chapter 17 – Rich Client Applications
  • Chapter 18 – Services
  • Chapter 19 – Mobile Applications
  • Chapter 20 – Office Business Applications (OBA)
  • Chapter 21 – SharePoint Line-Of-Business (LOB) Applications

   

Appendix

  • Cheat Sheet – patterns & practices Pattern Catalog
  • Cheat Sheet – Presentation Technology Matrix
  • Cheat Sheet – Data Access Technology Matrix
  • Cheat Sheet – Workflow Technology Matrix
  • Cheat Sheet – Integration Technology Matrix

As you can see, this book can be very useful and helpful for those programming using the .NET framework. I recommend you download and check it out. Have fun!

Jason

More Microsoft “How Do I” Video Updates and Service Pack 1 for 2008

I just wanted to mention that Microsoft officially launched the RTM version Service Pack 1 for Visual Studio 2008 a couple weeks ago. It includes many fixes and some other features and improvements. WPF (Windows Presentation Foundation) performance has been greatly increased as well. Click Here to check out the Service Pack for VB 2008.

Also Microsoft has been adding new How Do I videos for Visual Basic 2008 the past couple of months it appears. Its definitely worth checking out. It looks like Microsoft added many newer videos working with Excel and Microsoft Office and services. Linq and data-based programming looks to be updated as well. Remember that MSDN has many 2005 based videos as well. Anyways, Click Here if you want to check out the full list of MSDN’s “How Do I” video series. Have Fun!

             Jason

Readymade Options for Playback of Music/Audio Files in VB and VB.NET – 2 of 2

I finally got time to finish part two about options available to play audio or music files using Visual Basic 6.0 and Visual Basic .NET. This article will provide info on two 3rd Party libraries for audio playback with advanced features. They are both feature rich and provide many  advanced features. The first is the Bass.Dll Sound System and the second is the FMod.dll Sound System.

Both libraries are Free to use as long as the application’s using them are not commercial or compensated. If its a personal or freeware application they grant you a free license to use them. Bass.dll does have a lower cost option if your making a Shareware app. You should read through the license agreements of each library before using them in your applications.

Note: You can check out part one at this link.


 BASS.DLL Audio System Library

This is a great library for pretty much all of your music or audio needs. Bass can play everything from mp3’s, wave’s and mod music to .cda’s and internet streaming. It has alot of source code and examples for Visual Basic and Visual Basic.NET. This library gives you access to the samples that are playing so you can plot your own visualizations or ffts. I had alot of experience with this library a few years ago and even made the original VB.NET api and examples for the author. The .dll is very small in size (Under 100KB) so it won’t bloat your application.

Author Information: BASS is an audio library for use in Windows and Mac OSX software. Its purpose is to provide developers with powerful and efficient sample, stream (MP3, MP2, MP1, OGG, WAV, AIFF, custom generated, and more via add-ons), MOD music (XM, IT, S3M, MOD, MTM, UMX), MO3 music (MP3/OGG compressed MODs), and recording functions. All in a tiny DLL, under 100KB* in size.

On Windows, BASS requires DirectX 3 or above for output, and takes advantage of DirectSound and DirectSound3D hardware accelerated drivers, when available. On OSX, BASS uses CoreAudio for output, and OSX 10.3 or above is recommended. Both PowerPC and Intel Macs are supported.

C/C++, Delphi, Visual Basic, and MASM APIs are provided, with several examples to get you started. .Net and other APIs are also available.

 Main Features Main features
Samples
Support for WAV/AIFF/MP3/MP2/MP1/OGG and custom generated samples
Sample streams
Stream any sample data in 8/16/32 bit, with both “push” and “pull” systems
File streams
MP3/MP2/MP1/OGG/WAV/AIFF file streaming
Internet file streaming
Stream data from HTTP and FTP servers (inc. Shoutcast, Icecast & Icecast2), with proxy server support and adjustable buffering
Custom file streaming
Stream data from anywhere using any delivery method, with both “push” and “pull” systems
Multi-channel streaming
Support for more than plain stereo, including multi-channel OGG/WAV/AIFF files
MOD music
Uses the same engine as XMPlay (very accurate, efficient, high quality reproduction), with full support for all effects, filters, stereo samples, DMO effects, etc…
MO3 music
MODs with MP3 or OGG compressed samples (vastly reduced file size with virtually identical sound quality), MO3s are created using the MO3 encoder
Multiple outputs
Simultaneously use multiple soundcards, and move channels between them
Recording
Flexible recording system, with multiple device support and input selection, (WMA encoding & broadcasting via the add-on, and other formats via BASSenc)
Decode without playback
Streams and MOD musics can be outputted in any way you want (encoded, written to disk, streamed across a network, etc…)
Speaker assignment
Assign streams and MOD musics to specific speakers to take advantage of hardware capable of more than plain stereo (up to 4 separate stereo outputs with a 7.1 soundcard)
High precision synchronization
Synchronize events in your software to the streams and MOD musics, synchronize playback of multiple channels together
Custom DSP
Apply any effects that you want, in any order you want
DirectX 8 effects Windows only
Chorus / compressor / distortion / echo / flanger / gargle / parametric eq / reverb, 2 implementation options each with its benefits (including mixing with DSP functions)
32 bit floating-point decoding and processing
Floating-point decoding/rendering, DSP, FX, and recording
3D sound
Play samples/streams/musics in any 3D position, with EAX support
Flexible
Small buffers for realtime performance, large buffers for stability, automatic and manual buffer updating, configurable threading
Expandable
Add-on system for additional format support and effects (C/C++ API available on request), dynamic plugin loading system, access to underlying DirectSound objects
Small
BASS is less than 100KB*, so won’t bloat your distribution

As you can see, this is a very feature-rich and flexible sound system. If your interested in Bass.dll then go to the main webpage.


FMOD.dll Music and Sound Effects System

Continue reading

Readymade Options for Playback of Music/Audio Files in VB and VB.NET – 1 of 2

This article and Part Two are to show some options available for Audio/Music playback if your not interested in making your own control or library. I do have an article on how to do basic music playback at this link with some quick and simple source code. But if you want more advanced features and don’t want to create the bulk of the playback code, then the content in these articles should help you out. This first article is on using some libraries I made around the MCISendString Windows API function and doesn’t have 3rd party dependency.

Note: You can now check out part two at this link on two 3rd party controls named Bass.dll and FMod.dll.


Visual Basic 6.0

For VB 6.0 is Music Module v2.2 that I made with Visual Basic 6.0 and contains the main features that a music player usually needs. It supports the most popular music formats like Wave, MIDI, and MP3 files. Some other features are calculating the MP3’s overall Bitrate, getting the Playing Position in various formats, Left/Right Volume Control with Muting, etc. While the class module is old, it still does the job well and does not rely on any 3rd Party .DLL’s or Resources. You can download the Class Module with Example at this link.

Visual Basic.NET 2002/2003

This option is basically for VB.NET 2002/2003 and would recommend you use it for those versions only. This library is called csMusicLibrary v1.0 Professional. This class contains more features than the VB 6 library.  The class has all of the features required for a normal music player and some extra features like basic playlist support, setting the music playback rate, setting the playing position and more. IF your interested in this option you can download the compiled class with example at this link.

Visual Basic 2005/2008/2010, and Higher

This next library definitely has the most features out of the options in this article. It is a major overhaul of the original csMusicLibrary. It is csMusicLibrary v3.1 – The Professional Series and made with Visual Basic 2005. It is completely XML commented with explanations about the Subs/Functions and Properties along with remarks. There are many options available and is easy to use and understand. Besides your normal playback features it can give your applications some basic recording capabilities, extract MP3 Tag v1.1 information, get the music playback status, and much more. Like the other options outlined above, this library does not rely on any 3rd party controls or resources. If you don’t need any super advanced features like visualizations, data manipulation, or sound effects, etc. then this library should work just fine for making a fully featured music application. You can download the compiled class with example at this link.


All these options should be fine for making a nice featured application. But you may be wanting more advanced features like FFT’s, Data Manipulation, Sound FX, and so on. That is where the next article will come in. Click this link to read part two about some third party controls. Have fun 🙂

Jason

Revised: 2014

Play and Stop a Wave File or System Sound using VB 2005 and Higher

This shows how to use Visual Basic.NET 2005, VB 2008, Visual Basic 2010, and 2013 to play a wave (.wav) file and/or play a Windows SystemSound. This uses the MY interface which uses the SoundPlayer class new to .NET 2.0.

        '
        'This will Play a Wave file from the specified Path, Play a selected system Sound and Stop a sound that
        'is playing.
        '
        My.Computer.Audio.Play("C:\WINDOWS\Media\Windows XP Default.wav", AudioPlayMode.Background)

        My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)

        My.Computer.Audio.Stop()