Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Octave to read and write files under Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use Octave to read and write files under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Octave is a software similar to Matlab on Linux. It has a large number of functions and commands to support sound acquisition, recording, playback and digital processing of audio signals. It is used in entertainment applications, research, medicine and other scientific fields.

Environmental preparation

First install octave, run the following command on the Ubuntu terminal to add Octave PPA, and then install Octave.

Sudo apt-add-repository ppa:octave/stablesudo apt-get updatesudo apt-get install octave step 1: open Octave

In this step, we click the software icon to open Octave, and we can select the work path by clicking the drop-down button.

Step 2: audio information

Use the audioinfo command to view information about the audio file you want to process.

> > info = audioinfo ('testing.ogg') step 3: read the audio file

In this tutorial, I will use the ogg file to read the properties of this file, such as sampling, audio type (stereo and mono), number of channels, and so on. It is important to declare that all commands used in the tutorial are executed in the Octave terminal window. First, we have to assign the ogg file to a variable. Note: the file must be in the working path of Octave.

> > file='yourfile.ogg' > > [M, fs] = audioread (file)

Where M is an one-column or two-column matrix, depending on the number of channels, fs is the sampling rate.

You can read the audio file by doing the following:

> [y, fs] = audioread (filename, samples) > > [y, fs] = audioread (filename, datatype) > > [y, fs] = audioread (filename, samples, datatype)

Samples specifies the start and end frames, and datatype specifies the type of data to be returned. You can set values for all variables:

> > samples = [1, fs) > > [y, fs] = audioread (filename, samples)

Data type:

> > [YJEONFs] = audioread (filename,'native')

If the value is "native", its data type depends on how the data is stored in the audio file.

Step 4: write operation of audio file

Create a new ogg file:

We will create an ogg file from a cosine. The sampling rate is 44100 times per second, and this file is sampled for at least 10 seconds. The frequency of the cosine signal is 440 Hz.

> > filename='cosine.ogg'; > > fs=44100; > > tacti0VlGULTHANG FSPLO10; > > wimp2The pirates 440ft; > > signal=cos (w); > > audiowrite (filename, signal, fs)

This creates a 'cosine.ogg' file in the work path, which contains cosine signals.

Playing the 'cosine.ogg' file' will produce a 440Hz tone, which happens to be the'A 'tone in music theory. If you need to see the values saved in the file, you must use the 'audioread' function to read the file. In subsequent tutorials, we will see how to read an audio file in two channels.

Step 5: play the audio file

Octave has a default audio player that you can test with. Use the following function:

> > [yjingfs] = audioread ('yourfile.ogg'); > player=audioplayer (yjagfs, 8) scalar structure containing the fields: BitsPerSample = 8 CurrentSample = 0 DeviceID =-1 NumberOfChannels = 1 Running = off SampleRate = 44100 TotalSamples = Type = audioplayer UserData = [] (0x0) > play (player); these are all the contents of this article entitled "how to use Octave to read and write files under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report