3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Elixirでピコピコ音鳴らそう

Last updated at Posted at 2024-09-02

前提条件

  • OS Ubuntu 22.04

環境構築

soxのインストール

$ sudo apt install sox

プロジェクト作成

$ mix new sox

ソースを書く

lib/sox.ex
defmodule Sox do
  @moduledoc """
  Documentation for `Sox`.
  """

  @doc """
  Hello world.

  ## Examples

      iex> Sox.hello()
      :ok

  """
  def hello do
    1..10
    |> Enum.each(fn _ -> piko() end)
    :ok
  end

  def piko do
    play(0.1, 440)
    play(0.1, 880)
  end

  def play(t, f) do
    System.cmd("play", ~w"-n synth #{t} sin #{f}")
  end
end
test/sox_test.exs
defmodule SoxTest do
  use ExUnit.Case
  doctest Sox
  
end

実行

$ mix test

440Hzと880Hzの交互の音が鳴りました

ソース(github)

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?