Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This program will run on the computer I wrote it on, but will not run on other computers. The error that comes up on other computers is when the sound is set, which is a call to the dll. Any help would be greatly appreciated!

Here is the code from the program:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.DirectX.DirectSound;
using System.Media;
using WaveRecorder;
using System.Windows;

namespace SpellingBee
{

    public partial class AddQuizForm : Form
    {
 //Sound devices
        //Sound reference http://aaronamberman.com/tutorials/csaudio.php
        private SoundCapture sndCapt;
        private SoundDevices sndDevice;
        private Playback playBack;
        private bool isRecording = false;
        }
private void setSound()
        {
            //int sampling = 96000;
            //short bitSample = 16;
            //short chnls = 2;
            try
            {
                //Set and reset devices
                sndDevice = new SoundDevices(this);
                sndCapt = new SoundCapture(96000);
                sndCapt.OnWavComplete += new SoundCapture.Complete(sndCapt_OnWavComplete);
                
                //sndCapt = new SoundCapture(SoundCapture._96000_HZ, SoundCapture._16_Bit, SoundCapture._STEREO);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Concat(ex.StackTrace, ex.Message));
                if (ex.InnerException != null)
                {
                    MessageBox.Show("Sound could not be set at setSound()" + Environment.NewLine +
                        String.Concat(ex.InnerException.StackTrace, ex.InnerException.Message));
                }
            }
        }


This is the code from the dll:

C#
public SoundCapture(int samplingRate)
        {
            if (samplingRate < 11025) samplingRate = 11025;
            else if (samplingRate > 11025 && samplingRate < 22050) samplingRate = 22050;
            else if (samplingRate > 22050 && samplingRate < 44100) samplingRate = 44100;
            else if (samplingRate > 44100 && samplingRate < 96000) samplingRate = 96000;
            else if (samplingRate > 96000) samplingRate = 96000;

            wvFrmt = new WaveFormat();
            wvFrmt.SamplesPerSecond = samplingRate;

            if (samplingRate <= 22050) wvFrmt.BitsPerSample = 8;
            else if (samplingRate >= 44100) wvFrmt.BitsPerSample = 16;

            if (samplingRate <= 22050) wvFrmt.Channels = 1;
            else if (samplingRate >= 44100) wvFrmt.Channels = 2;

            wvFrmt.FormatTag = WaveFormatTag.Pcm;

            wvFrmt.BlockAlign = (short)(wvFrmt.Channels * (wvFrmt.BitsPerSample / 8));
            wvFrmt.AverageBytesPerSecond = wvFrmt.SamplesPerSecond * wvFrmt.BlockAlign;

            cpturBffrDesc = new CaptureBufferDescription();
            cpturBffrDesc.BufferBytes = wvFrmt.AverageBytesPerSecond;
            cpturBffrDesc.ControlEffects = false;
            cpturBffrDesc.Format = wvFrmt;
            cpturBffrDesc.WaveMapped = true;

            cptur = new Capture();

            cptrBffr = new CaptureBuffer(cpturBffrDesc, cptur);//This is where the 2nd part of the error is listed

            rawSoundData = new List<byte[]>();

            SetCaptureNotifications();


I have run the msi file on the computer I created this with and it runs fine, other computers have same os and everything but won't run?
Posted
Updated 9-Mar-12 9:45am
v3
Comments
Dave Kreskowiak 9-Mar-12 13:23pm    
...and the error would be.....????
OriginalGriff 9-Mar-12 13:59pm    
...really useful...:sigh:
James M. White 9-Mar-12 14:12pm    
The errors lines are shown in the code and commented out. One is where the call is made to the SoundCapture() in the program and the other is in the dll at the cptrBffr = new CaptureBuffer(cpturBffrDesc, cptur);
[no name] 9-Mar-12 14:14pm    
Yes we see that but that does not tell us what the error message that YOU are seeing is.
James M. White 9-Mar-12 14:25pm    
Catch statement then,

Error in the application. at Microsoft.DirectX.DirectSound.CaptureBuffer..ctor(CaptureBufferDescription desc, Capture parent)
at WaveRecorder.SoundCapture..ctor(Int32samplingRate)
at SpellingNee.AddQuizForm.setSound()

You are missing this line in your listing:
captureBufferDesc = new CaptureBufferDescription();
 
Share this answer
 
Comments
James M. White 9-Mar-12 14:26pm    
I actually took that out of the code trying to fix this problem and forgot to add it back in. The problem was there with the line of code in there.
I met the same problem. But it was cured somehow when I compiled the program in Debug mode.
Note that there's still a problem in Release mode.
 
Share this answer
 
Comments
Dave Kreskowiak 11-Jan-16 22:57pm    
Don't put this as an answer to a 3 year old question. It really didn't add anything to the discussion at all as compiling an app is Debug config doesn't really solve the problem for a Release mode compile.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900