Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:20:19+00:00 2026-05-31T10:20:19+00:00

I am using code that uses the following subfunction: function playTone (duration, toneFreq) %

  • 0

I am using code that uses the following subfunction:

function playTone (duration, toneFreq)
% Generate a tone

samplesPerSecond = 44100; % the bit rate of the tone
y = sin(linspace(0, duration * toneFreq * 2 * pi, round(duration * samplesPerSecond))); % the equation of the sound wave
player = audioplayer(y, samplesPerSecond); % create an audio object from the sound wave at the specified bit rate
playblocking(player) % play the audio, blocking control until the sound completes

This function is called, for example, with the following:

playTone(4, 400);

This causes a sound to play at 400Hz, lasting for 4 seconds.

The problem is, the function playblocking() restricts control until the sound has completed. The alternative is to use play(), which means that no sound plays at all (because sound stops as soon as the function completes).

I can’t use the sound() function due to a known bug in my version of MATLAB… How can I make the audioplayer() function play a sound without taking control of the system, if the sound is created within a subfunction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:20:20+00:00Added an answer on May 31, 2026 at 10:20 am

    You can define player variable as global. Just put this line in the beginning of the function:

    global player
    

    Although it’s considered not a good programming practice, it may work for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following C# code that uses DLLImport. using System; namespace LvFpga {
I have some code that uses ODP.Net using (OracleConnection connection = new OracleConnection(connectionString)) {
This is the code that I'm using to generate a DH keypair: KeyPairGenerator keyGen
I'm using NetBeans as my IDE. Whenever I have some code that uses another
I have the following code that uses a for loop and I would like
I have the following code that uses Sequence objects to read data from a
I have the following code that uses the SqlClient.ExecuteScalar method to return an ID
I'm trying to convert to Java some code that uses SDL. I'm using the
I've the following code that uses jQueryMobile Sliders: <!DOCTYPE html> <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta
i'm using that code for encrypt a string with 3DES in IOS and i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.