言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

AudioClip.Create

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function Create(name: string, lengthSamples: int, channels: int, frequency: int, _3D: bool, stream: bool, pcmreadercallback: PCMReaderCallback, pcmsetpositioncallback: PCMSetPositionCallback): AudioClip;
public static AudioClip Create(string name, int lengthSamples, int channels, int frequency, bool _3D, bool stream, PCMReaderCallback pcmreadercallback, PCMSetPositionCallback pcmsetpositioncallback);
public static def Create(name as string, lengthSamples as int, channels as int, frequency as int, _3D as bool, stream as bool, pcmreadercallback as PCMReaderCallback, pcmsetpositioncallback as PCMSetPositionCallback) as AudioClip

Description

名前、与えられたサンプルの長さ、チャンネル、周波数からユーザーがAudioClipを作成します。

SetData で独自のオーディオデータを設定します。 クリップのデータ読み取りと位置の変更をする時に必ずコールバックを取得するために PCMReaderCallbackPCMSetPositionCallback デリゲートを使います。 stream引数がtrueの場合には、必要に応じて小さくまとまったデータを読み取り、コールバック関数の引数として渡します。falseの場合は、作成時、一度にすべてを読み込みます。

	#pragma strict
	// Creates a 1 sec long audioclip, with a 440hz sinoid
	var position: int = 0;
	var sampleRate : int = 0;
	var frequency : float = 440;
	function Start () {
		var myClip = AudioClip.Create("MySinoid", 44100, 1, 44100, false, true, OnAudioRead, OnAudioSetPosition);
		sampleRate = AudioSettings.outputSampleRate;

		audio.clip = myClip;
		audio.Play();
	}

	function OnAudioRead(data:float[])
	{
		for (var count = 0; count < data.Length; count++)
		{
			data[count] = Mathf.Sign(Mathf.Sin(2 * Mathf.PI * frequency * position / sampleRate));
			position++;
		}
	}

	function OnAudioSetPosition(newPosition:int)
	{
		position = newPosition;
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public int position = 0;
    public int sampleRate = 0;
    public float frequency = 440;
    void Start() {
        AudioClip myClip = AudioClip.Create("MySinoid", 44100, 1, 44100, false, true, OnAudioRead, OnAudioSetPosition);
        sampleRate = AudioSettings.outputSampleRate;
        audio.clip = myClip;
        audio.Play();
    }
    void OnAudioRead(float[] data) {
        int count = 0;
        while (count < data.Length) {
            data[count] = Mathf.Sign(Mathf.Sin(2 * Mathf.PI * frequency * position / sampleRate));
            position++;
            count++;
        }
    }
    void OnAudioSetPosition(int newPosition) {
        position = newPosition;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public position as int = 0

	public sampleRate as int = 0

	public frequency as float = 440

	def Start() as void:
		myClip as AudioClip = AudioClip.Create('MySinoid', 44100, 1, 44100, false, true, OnAudioRead, OnAudioSetPosition)
		sampleRate = AudioSettings.outputSampleRate
		audio.clip = myClip
		audio.Play()

	def OnAudioRead(data as (float)) as void:
		count as int = 0
		while count < data.Length:
			data[count] = Mathf.Sign(Mathf.Sin(((((2 * Mathf.PI) * frequency) * position) / sampleRate)))
			position++
			count++

	def OnAudioSetPosition(newPosition as int) as void:
		position = newPosition