Thread Subject: Using slider to updating audio signal being played..real post tia

Subject: Using slider to updating audio signal being played..real post tia

From: Rick T

Date: 9 Feb, 2010 21:47:29

Message: 1 of 2

Sorry if this got posted twice gremlins started playing with my
computers.

Greetings All

I'm trying to use a slider to adjust the frequency of an audio signal
that is played out my audio card in "realtime" using matlab. I keep
getting an error reference to non-existent field 'freq'.
this is the line of code it saying has the error
 set(handles.freq,'Value',sliderValue);

The thing is I created the freq variable right above it. Any
suggestions/ should I be doing it this way?

example code below:

function slider1_Callback(hObject, eventdata, handles)

sliderValue = get(handles.slider1,'Value');
%puts the slider value into the edit text component
set(handles.sliderValue_editText,'String', num2str(sliderValue));

freq=1;
set(handles.freq,'Value',sliderValue); %sets freq when slider changes
%-------error it refers too above

% Update handles structure
guidata(hObject, handles);

function sliderValue_editText_Callback(hObject, eventdata, handles)

sliderValue = get(handles.sliderValue_editText,'String');
 %convert from string to number if possible, otherwise returns empty
sliderValue = str2num(sliderValue);

%if user inputs something is not a number, or if the input is less
than 0
%or greater than 100, then the slider value defaults to 0
if (isempty(sliderValue) || sliderValue < 0 || sliderValue > 300)
    set(handles.slider1,'Value',0);
    set(handles.freq,'Value',1); %sets freq when slider changes
    set(handles.sliderValue_editText,'String','0');
else
    set(handles.slider1,'Value',sliderValue);
    set(handles.freq,'Value',sliderValue); %sets freq when slider
changes
end


function freq_Callback(hObject, eventdata, handles)
ao=analogoutput('winsound');
ao.samplerate=44100;
y = sin(freq*(0:(2*pi/44100):2*pi))'; % creates test signal from freq
variable

chan=addchannel(ao,1:2);
ao.RepeatOutput = 3; % to output 3 times you need to repeat 3 USE
RepeatOutput
putdata(ao,[y y])
start(ao)

% Don't forget to cleanup when done
clear ao
%delete(ao)

Subject: Using slider to updating audio signal being played..real post

From: Walter Roberson

Date: 9 Feb, 2010 22:10:01

Message: 2 of 2

Rick T wrote:

> function slider1_Callback(hObject, eventdata, handles)
>
> sliderValue = get(handles.slider1,'Value');
> %puts the slider value into the edit text component
> set(handles.sliderValue_editText,'String', num2str(sliderValue));
>
> freq=1;

That line creates a variable named 'freq', not a variable named 'handles.freq'.

> set(handles.freq,'Value',sliderValue); %sets freq when slider changes
> %-------error it refers too above
>
> % Update handles structure
> guidata(hObject, handles);

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com